简体   繁体   中英

Webpack / How to not bundle JS files in dev mode?

Basically, by default, the main point of webpack is to bundle every parsed JS files into a bundle.js .

In dev mode, I would like to have access to each JS separately. I don't want them to be bundled in one file.

Is there a way to prevent webpack to concat files into bundle.js in dev mode?

I would like to see A.js , B.js , C.js when I open the source code of the page in dev mode, and not bundle.js that gathers them.

One thing that pops out of my head is that you can configure webpack's entry and output properties. By doing so, you are telling webpack to treat each entry separately and it will give you output files with the names of the 'key' in the entry object. See below for example:

// webpack.dev.js

entry: {
  A: 'src/js/A.js',
  B: 'src/js/B.js',
  C: 'src/js/C.js'
},

output: {
 path: 'dist',
 filename: '[name].js'
}

This will produce A.js, B.js and C.js.

More information from the documentation here: https://webpack.github.io/docs/configuration.html#entry

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM