2016-05-10 10 views
2

Ich habe zwei Konfigurationen für Webpack erstellt.webpack watch option während multi config

Wenn ich ein Array von Konfigurationen exportieren: alles funktioniert, anstelle der Option beobachten. Die Aufgaben enden einfach (mit Erfolg).

Wenn ich eine Konfigurationsexport testen - Uhr funktioniert gut.

Ich habe mehrere Einstiegspunkte ausprobiert, und sah auch gut funktioniert diese Zeit, aber Config sah ein wenig unordentlich aus.

Ich werde meine Configs, hoffe auf Ratschläge, danke.

/* FRONT-END CONFIG */ 
var frontWebpackConfig = { 
    entry: "./src/front/app", 

    output: { 
    path: __dirname + "/build", 
    filename: "public/app.js" 
    }, 

    watch: NODE_ENV == "development", 

    watchOptions : { 
    aggregateTimeout: 100 
    }, 

    devtool : NODE_ENV == "development" ? "cheap-inline-module-source-map" : null, 

    plugins : [ 
    new webpack.NoErrorsPlugin(), 
    new webpack.DefinePlugin({ 
     NODE_ENV : JSON.stringify(NODE_ENV) 
    }) 
    ], 

    module : { 
    loaders : [ 
     { 
     test : /\.js$/, 
     loader : 'babel', 
     query: { 
      presets: ['es2015'] 
     } 
     }, 
     { test: /\.css$/, loader: "style-loader!css-loader" } 
    ] 
    } 
}; 


/* BACK-END CONFIG */ 
var backWebpackConfig = { 
    entry: "./src/back/server", 

    target : 'node', 

    output: { 
    path: __dirname + "/build", 
    filename: "server.js" 
    }, 

    externals: nodeModules, 

    watch: NODE_ENV == "development", 

    watchOptions : { 
    aggregateTimeout: 100 
    }, 

    devtool : NODE_ENV == "development" ? "cheap-inline-module-source-map" : null, 

    plugins : [ 
    new webpack.NoErrorsPlugin(), 
    new webpack.DefinePlugin({ 
     NODE_ENV : JSON.stringify(NODE_ENV) 
    }) 
    ], 

    module : { 
    loaders : [ 
     { 
     test : /\.js$/, 
     loader : 'babel', 
     query: { 
      presets: ['es2015'] 
     } 
     } 
    ] 
    } 
} 


/* EXPORTS */ 
module.exports = [frontWebpackConfig, backWebpackConfig] 

Auch ich habe diese Ausdrücke cheked: „NODE_ENV ==‚Entwicklung‘“ Wert und versuchte wahr direkt einzustellen.

Update: lustige Sache, ich habe gerade versucht, mit "--watch" -Option in der Befehlszeile zu starten und es hat gut funktioniert. Irgendwelche Ideen warum Dateikonfiguration nicht funktioniert?

Antwort

1

Eigentlich gibt für watch in webpack 1.13.0+ eine Option.

Es scheint jedoch, dass im Falle mehrerer Konfigurationen (Array von Objekten) watch Eigenschaft auf das Array festgelegt werden sollte, damit es funktioniert. Schließlich würde watchOptions Eigenschaft des ersten Konfigurationsobjekts verwendet werden.

/* FRONT-END CONFIG */ 
var frontWebpackConfig = { 
    entry: "./src/front/app", 
    // ... 
    watch: NODE_ENV == "development", 
    watchOptions : { 
     aggregateTimeout: 100, 
    }, 
}; 

/* BACK-END CONFIG */ 
var backWebpackConfig = { 
    entry: "./src/back/server", 
    // ... 
}; 

var configuration = [frontWebpackConfig, backWebpackConfig]; 
configuration.watch = true; 

/* EXPORTS */ 
module.exports = configuration; 

--watch Argument in der Kommandozeile setzt nur watch Eigenschaft auf dem Feld während der Konfiguration Laden und Verarbeitung, deshalb Argument CLI funktioniert, wie es erwartet wird.

Verwandte Themen