You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
webpack statically parses for `require.ensure()` in the code while building and adds the modules here into a separate chunk. This new chunk is loaded on demand by webpack through jsonp.
This is an array of strings where we can declare all the modules that need to be made available before all the code in the callback function can be executed.
This is the callback function that webpack will execute once the dependencies are loaded. An implementation of the require object is sent as a parameter to this function. This is so that, we can further `require()` the dependencies and any other modules for execution.
The chunkName is the name given to the chunk created by this particular `require.ensure()`. By giving the same name at different split points of `require.ensure()`, we can make sure all the dependencies are collectively put in the same bundle.
?> `require.ensure`relies on `Promises` internally. If you use `require.ensure`with older browsers, remember to shim `Promise.`[es6-promise polyfill](https://github.com/stefanpenner/es6-promise).
The above code ensures that a split point is created and `a.js`is bundled separately by webpack.
90
+
以上代码保证了拆分点被创建,而且 `a.js`被 webpack 分开打包。
91
91
92
-
### Dependencies as Parameter
92
+
### 依赖作为参数
93
93
94
94
```javascript
95
95
require.ensure(['./a.js'], function(require) {
96
96
require('./b.js');
97
97
});
98
98
```
99
99
100
-
In the above code, `a.js` and `b.js` are bundled together and split from the main bundle. But only the contents of `b.js` are executed. The contents of `a.js` are only made available and not executed.
101
-
To execute `a.js`, we will have to require it in a sync manner like `require('./a.js')` for the JavaScript to get executed.
0 commit comments