Code Splitting in Webpack 4 - Bundle Loader
Dec 9, 2016
Today I will show you how to do code splitting use bundle-loader.
What bundle-loader does is to make each require('bundle-loader!xxx.js') to a Promise. Then it will load the module asynchronously from another chunk.
Let’s look at an example.
The example
We have a entry point example.js which will use bundle-loader to load file.js.
|
|
The configuration we use is:
|
|
After we run the command webpack, we will get the following result:
|
|
Because we use bundle-loader to load file.js, webpack has generated a separate chunk to contains file.js. We can verify it by check inside those 2 chunk files:
output.jsis the entry chunk. It contains theexample.js0.output.jscontainsfile.js
That’s all for today! Thanks!
