webpack
Version:
Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.
90 lines (62 loc) • 1.98 kB
Markdown
This example show how to use multiple entry points with a commons chunk.
In this example you have two (HTML) pages `pageA` and `pageB`. You want to create individual bundles for each page. In addition to this you want to create a shared bundle that contains all modules that used in both pages (assuming there are many/big modules in common). The pages also use Code Splitting to load a less used part of the features on demand.
You can see how to define multiple entry points via the `entry` option and the required changes (`[name]`) in the `output` option. You can also see how to use the CommonsChunkPlugin.
You can see the output files:
* `commons.js` contains:
* the module system
* chunk loading logic
* module `common.js` which is used in both pages
* `pageA.bundle.js` contains: (`pageB.bundle.js` is similar)
* the entry point `pageA.js`
* it would contain any other module that is only used by `pageA`
* `0.chunk.js` is an additional chunk which if used by both pages. It contains:
* module `shared.js`
You can also see the info that is printed to console. It shows among others:
* the generated files
* the chunks with file, name and id
* see lines starting with `chunk`
* the modules that are in this chunks
* the reasons why the modules are included
* the reasons why a chunk is created
* see lines starting with `>`
# pageA.js
``` javascript
{{pageA.js}}
```
# pageB.js
``` javascript
{{pageB.js}}
```
# webpack.config.js
``` javascript
{{webpack.config.js}}
```
# pageA.html
``` html
{{pageA.html}}
```
# js/commons.js
``` javascript
{{js/commons.js}}
```
# js/pageA.bundle.js
``` javascript
{{js/pageA.bundle.js}}
```
# js/pageB.bundle.js
``` javascript
{{js/pageB.bundle.js}}
```
# js/0.chunk.js
``` javascript
{{js/0.chunk.js}}
```
# Info
## Uncompressed
```
{{stdout}}
```
## Minimized (uglify-js, no zip)
```
{{min:stdout}}
```