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
在Webpack CLI中指定条目数组_Webpack - Fatal编程技术网

在Webpack CLI中指定条目数组

在Webpack CLI中指定条目数组,webpack,Webpack,在配置中,我们将指定一个如下所示的条目数组: entry: [ 'polyfills', './src/index.js' ] 我想知道是否可以通过CLI指定: $ webpack [opts] <entry_array?> <output> $webpack[opts] 清楚地说,我指的是一个包含模块数组的单个条目,而不是多个条目(我理解这是可能的)。您可以简单地将所有条目点作为参数传递,它们将被视为单个块,就像在配置中使用数组一样。在您的情况下,以下内容

在配置中,我们将指定一个如下所示的条目数组:

entry: [
  'polyfills',
  './src/index.js'
]
我想知道是否可以通过CLI指定:

$ webpack [opts] <entry_array?> <output>
$webpack[opts]

清楚地说,我指的是一个包含模块数组的单个条目,而不是多个条目(我理解这是可能的)。

您可以简单地将所有条目点作为参数传递,它们将被视为单个块,就像在配置中使用数组一样。在您的情况下,以下内容将创建一个
bundle.js
,其中包含
polyfills
/src/index.js

webpack polyfills ./src/index.js bundle.js
为了消除关于多个块的任何混淆,CLI接受
=
形式的参数,其工作方式与在配置中使用对象类似。因此,下面将生成一个带有相应入口点的
polyfills.bundle.js
和一个
app.bundle.js

webpack polyfills=polyfills app=./src/index.js [name].bundle.js
注意:如果输出是一个文件,webpack将抱怨存在冲突


有关更多详细信息,请查看官方文档。

@Michael,我也遇到过同样的问题,将多个条目合并到一个输出文件时出错。我在webpack cli中这样做只是为了练习

选择二,我得到

npx webpack index=./src/index.js app=./src/index2.js [name].bundle.js
zsh: no matches found: [name].bundle.js 
选项1,它是

npx webpack ./src/index.js ./src/index2.js dist/bundle.js
Hash: fe5cb8d967e4e39a16b8
Version: webpack 4.32.0
Time: 105ms
Built at: 2019-05-22 11:01:35
 1 asset
Entrypoint main = main.js
[0] multi ./src/index.js ./src/index2.js dist/bundle.js 52 bytes {0} [built]
[1] ./src/index.js 27 bytes {0} [built]
[2] ./src/index2.js 27 bytes {0} [built]

...

ERROR in multi ./src/index.js ./src/index2.js dist/bundle.js
Module not found: Error: Can't resolve 'dist/bundle.js' in '/Users/.../Code/webpack-pitfalls'
 @ multi ./src/index.js ./src/index2.js dist/bundle.js main[2]