当webpack.config文件导出多个配置时,选择一个webpack配置
像这样的当webpack.config文件导出多个配置时,选择一个webpack配置,webpack,Webpack,像这样的webpack.config.js文件可以导出多个配置: module.exports = [{entry: 'a.js'}, {entry: 'b.js'}]; 调用webpack时,如何从CLI中选择一个配置?当前无法从CLI的阵列中选择一个配置。最好是创建两个额外的配置文件(每个文件引用主文件中两个配置中的一个),并将webpack指向该配置 例如: webpack.a.config.js var allConfig = require('./webpack.config.js'
webpack.config.js
文件可以导出多个配置:
module.exports = [{entry: 'a.js'}, {entry: 'b.js'}];
调用webpack时,如何从CLI中选择一个配置?当前无法从CLI的阵列中选择一个配置。最好是创建两个额外的配置文件(每个文件引用主文件中两个配置中的一个),并将webpack指向该配置 例如:
webpack.a.config.js
var allConfig = require('./webpack.config.js');
module.exports = allConfig[0];
然后使用
--config Webpack.a.config.js调用Webpack。在Webpack 3.2中,您可以使用--config name
标志提供配置名称。您的配置应具有name属性 试试这个:
// webpack.config.js
export default [
webpackConfig1,
webpackConfig2,
]
function webpackConfig1(){
return {
name: "main",
entry: ["main.js"],
}
}
function webpackConfig2(){
return {
name: "other",
entry: ["other.js"],
}
}
webpack // compiles both configs
webpack --config-name main // only with name=main
webpack --config-name other // only with name=other
用法:
// webpack.config.js
export default [
webpackConfig1,
webpackConfig2,
]
function webpackConfig1(){
return {
name: "main",
entry: ["main.js"],
}
}
function webpackConfig2(){
return {
name: "other",
entry: ["other.js"],
}
}
webpack // compiles both configs
webpack --config-name main // only with name=main
webpack --config-name other // only with name=other
是的,我知道这种方法。我正在部分查找多配置webpack.config.js文件。我为webpack打开了一个问题: