webpack/examples/code-splitting-harmony/template.md

34 lines
770 B
Markdown
Raw Normal View History

2015-09-03 17:36:30 +08:00
This example show how to use Code Splitting with the ES6 module syntax.
The standard `import` is sync.
`import(module: string) -> Promise` can be used to load modules on demand. This acts as a split point for webpack and creates a chunk.
2015-09-03 17:36:30 +08:00
Providing dynamic expressions to `import` is possible. The same limits as with dynamic expressions in `require` calls apply here. Each possible module creates an additional chunk. In this example `import("c/" + name)` creates two additional chunks (one for each file in `node_modules/c/`). This is called "async context".
2015-09-03 17:36:30 +08:00
# example.js
```javascript
_{{example.js}}_
2015-09-03 17:36:30 +08:00
```
# dist/output.js
2015-09-03 17:36:30 +08:00
```javascript
_{{dist/output.js}}_
2015-09-03 17:36:30 +08:00
```
# Info
## Unoptimized
2015-09-03 17:36:30 +08:00
```
_{{stdout}}_
2015-09-03 17:36:30 +08:00
```
## Production mode
2015-09-03 17:36:30 +08:00
```
_{{production:stdout}}_
2015-09-03 17:36:30 +08:00
```