2015-05-22 04:36:16 +08:00
This example shows how to use multiple entry points with a commons chunk.
2014-07-24 17:29:49 +08:00
2015-05-22 04:36:16 +08:00
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 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.
2014-07-24 17:29:49 +08:00
2018-01-20 00:06:59 +08:00
You can see how to define multiple entry points via the `entry` option.
2018-02-21 22:21:05 +08:00
You can use
2014-07-24 17:29:49 +08:00
You can see the output files:
2019-04-05 05:04:47 +08:00
- `commons.js` contains:
- module `common.js` which is used in both pages
- `pageA.js` contains: (`pageB.js` is similar)
- the module system
- chunk loading logic
- the entry point `pageA.js`
- it would contain any other module that is only used by `pageA`
2019-05-10 03:34:28 +08:00
- `406.js` is an additional chunk which is used by both pages. It contains:
2019-04-05 05:04:47 +08:00
- module `shared.js`
2014-07-24 17:29:49 +08:00
You can also see the info that is printed to console. It shows among others:
2019-04-05 05:04:47 +08:00
- the generated files
- the chunks with file, name and id
- see lines starting with `chunk`
- the modules that are in the chunks
- the reasons why the modules are included
- the reasons why a chunk is created
- see lines starting with `>`
2014-07-24 17:29:49 +08:00
2013-11-20 01:09:26 +08:00
# pageA.js
2019-04-05 05:04:47 +08:00
```javascript
_{{pageA.js}}_
2013-11-20 01:09:26 +08:00
```
# pageB.js
2019-04-05 05:04:47 +08:00
```javascript
_{{pageB.js}}_
2013-11-20 01:09:26 +08:00
```
# webpack.config.js
2019-04-05 05:04:47 +08:00
```javascript
_{{webpack.config.js}}_
2013-11-20 01:09:26 +08:00
```
2013-12-03 16:27:15 +08:00
# pageA.html
2019-04-05 05:04:47 +08:00
```html
_{{pageA.html}}_
2013-12-03 16:27:15 +08:00
```
2018-01-05 04:39:29 +08:00
# dist/commons.js
2013-12-03 16:27:15 +08:00
2019-04-05 05:04:47 +08:00
```javascript
_{{dist/commons.js}}_
2013-12-03 16:27:15 +08:00
```
2018-01-20 00:06:59 +08:00
# dist/pageA.js
2013-11-20 01:09:26 +08:00
2019-04-05 05:04:47 +08:00
```javascript
_{{dist/pageA.js}}_
2013-11-20 01:09:26 +08:00
```
2018-01-20 00:06:59 +08:00
# dist/pageB.js
2013-11-20 01:09:26 +08:00
2019-04-05 05:04:47 +08:00
```javascript
_{{dist/pageB.js}}_
2013-11-20 01:09:26 +08:00
```
2019-05-10 03:34:28 +08:00
# dist/52.js
2013-11-20 01:09:26 +08:00
2019-04-05 05:04:47 +08:00
```javascript
2019-05-10 03:34:28 +08:00
_{{dist/52.js}}_
2013-11-20 01:09:26 +08:00
```
# Info
2017-12-14 17:09:09 +08:00
## Unoptimized
2013-11-20 01:09:26 +08:00
```
2019-04-05 05:04:47 +08:00
_{{stdout}}_
2013-11-20 01:09:26 +08:00
```
2017-12-14 17:09:09 +08:00
## Production mode
2013-11-20 01:09:26 +08:00
```
2019-04-05 05:04:47 +08:00
_{{production:stdout}}_
2013-11-20 01:09:26 +08:00
```