Jessica Robertson
Jessica Robertson

Reputation: 427

webpack multiple entries in a directory

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?

Upvotes: 0

Views: 5644

Answers (3)

Khalid Azam
Khalid Azam

Reputation: 1643

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

Upvotes: 0

crs0910
crs0910

Reputation: 1

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

Upvotes: 0

Kwan Ung Park
Kwan Ung Park

Reputation: 158

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.

Upvotes: 5

Related Questions