Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Webpack表示CLI中的条目名称_Node.js_Webpack - Fatal编程技术网

Node.js Webpack表示CLI中的条目名称

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

我想从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 = 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包中?