webpack/examples/code-splitting/template.md

63 lines
1.3 KiB
Markdown
Raw Normal View History

2015-05-22 04:36:16 +08:00
This example illustrates a very simple case of Code Splitting with `require.ensure`.
2014-07-24 17:29:49 +08:00
- `a` and `b` are required normally via CommonJS
- `c` is made available(,but doesn't get execute) through the `require.ensure` array.
- webpack will load it on demand
- `b` and `d` are required via CommonJs in the `require.ensure` callback
- webpack detects that these are in the on-demand-callback and
- will load them on demand
- webpack's optimizer can optimize `b` away
- as it is already available through the parent chunks
2014-07-24 17:29:49 +08:00
You can see that webpack outputs two files/chunks:
- `output.js` is the entry chunk and contains
- the module system
- chunk loading logic
- the entry point `example.js`
- module `a`
- module `b`
- `1.output.js` is an additional chunk (on-demand loaded) and contains
- module `c`
- module `d`
2014-07-24 17:29:49 +08:00
You can see that chunks are loaded via JSONP. The additional chunks are pretty small and minimize well.
2012-04-05 20:59:01 +08:00
# example.js
```javascript
_{{example.js}}_
2012-04-05 20:59:01 +08:00
```
# dist/output.js
2012-04-05 20:59:01 +08:00
```javascript
_{{dist/output.js}}_
2012-04-05 20:59:01 +08:00
```
2019-05-10 03:34:28 +08:00
# dist/796.output.js
2012-04-05 20:59:01 +08:00
```javascript
2019-05-10 03:34:28 +08:00
_{{dist/796.output.js}}_
2012-04-05 20:59:01 +08:00
```
Minimized
```javascript
2019-05-10 03:34:28 +08:00
_{{production:dist/796.output.js}}_
2012-04-05 20:59:01 +08:00
```
# Info
## Unoptimized
2012-04-05 20:59:01 +08:00
```
_{{stdout}}_
2012-04-05 20:59:01 +08:00
```
## Production mode
2012-04-05 20:59:01 +08:00
```
_{{production:stdout}}_
2012-04-05 20:59:01 +08:00
```