webpack multiple entries in a directory

2019-09-14 18:43发布

context: path.join(__dirname, 'resources/assets/bundle/js'),
  entry: [
    'webpack/hot/dev-server',
    'webpack-hot-middleware/client',
    './*.js'
  ]

Is above code even valid? instead of specifying every single file like

context: path.join(__dirname, 'resources/assets/bundle/entries'),
  entry: [
    'webpack/hot/dev-server',
    'webpack-hot-middleware/client',
    './abc.js',
    './def.js'
  ]

how can I include entire folder?

3条回答
叼着烟拽天下
2楼-- · 2019-09-14 19:31

You can easily do this by your own, as the webpack.config.js is just a node.js module and allows to execute any code. Wildcards in entry points

查看更多
Explosion°爆炸
3楼-- · 2019-09-14 19:37

Webpack uses entry point to resolve the reference to generate the bundle. you can define multiple entry point based on the number of bundle needed. you should not be adding entire folder as entry point, it means you want bundle of each file inside the folder, which webpack does not recommend.

https://webpack.github.io/docs/multiple-entry-points.html

查看更多
贪生不怕死
4楼-- · 2019-09-14 19:38

Why do you use the entire folder?

if you want entire folder , you can use glob npm module

As explained : https://github.com/webpack/webpack/issues/370

var glob = require("glob");
// ...
entry: glob.sync("./src/scripts/*.js")

but webpack is not recommended entire folder, the entry value should resolve to a specific file, or a list of specific files.

查看更多
登录 后发表回答