Node.js Webpack表示CLI中的条目名称
我想从CLI中为编译多个Sass主题指明我的条目名 My package.json:Node.js Webpack表示CLI中的条目名称,node.js,webpack,Node.js,Webpack,我想从CLI中为编译多个Sass主题指明我的条目名 My package.json: ./node_modules/.bin/webpack --config ./app/Resources/build/webpack.dev.js --progress --colors --watch THEME_NAME 我在我的webpack.config.js中恢复主题名称: var processArguments = process.argv; var theme = p
./node_modules/.bin/webpack
--config ./app/Resources/build/webpack.dev.js
--progress
--colors
--watch THEME_NAME
我在我的webpack.config.js中恢复主题名称:
var processArguments = process.argv;
var theme = processArguments[7]; // Return theme name
entryApp: {
app: './app/Resources/private/js/app.js',
theme: './app/Resources/private/scss/themes/' + theme + '/' + theme + '.scss'
},
并将其添加到myentryApp中:
var processArguments = process.argv;
var theme = processArguments[7]; // Return theme name
entryApp: {
app: './app/Resources/private/js/app.js',
theme: './app/Resources/private/scss/themes/' + theme + '/' + theme + '.scss'
},
但我有一个错误:
未找到输入模块中的错误
我绝对相信这条路是好的:(
有人能帮我吗
谢谢!webpack CLI的任何参数都被解释为入口点() 当你打电话时:
webpack [options] myTheme
它试图找到模块myTheme
,就像您在配置中将其指定为入口点一样
为此,您需要使用另一种方法。一种可能是使用环境变量
THEME=myTheme webpack [options]
然后,您可以使用配置中的process.env.THEME
访问它
或者,您可以将函数导出为webpack config,它返回配置对象。webpack CLI将向函数传递使用--env
CLI选项指定的任何选项。请参阅
对于隐式返回配置对象的arrow函数,它将如下所示:
module.exports = env => ({
entry: {
entryApp: {
app: './app/Resources/private/js/app.js',
theme: './app/Resources/private/scss/themes/' + env.theme + '/' + env.theme + '.scss'
},
}
// Rest of your config
});
您可以按如下方式调用webpack:
webpack --env.theme=myTheme [other options]
向我们展示processArguments数组-主题是否传递到Web包中?