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
Also added deprecation note. I think describing it with `import()` instead of just `import` will cause less of a headache for newcomers who don't know the difference between `import from` and `import()`.
The ES2015 Loader spec defines `System.import` as method to load ES2015 Modules dynamically on runtime.
276
+
The ES2015 Loader spec defines `import()` as method to load ES2015 Modules dynamically on runtime.
277
277
278
-
webpack treats `System.import` as a split-point and puts the requested module in a separate chunk.
278
+
webpack treats `import()` as a split-point and puts the requested module in a separate chunk.
279
279
280
-
`System.import` takes the module name as argument and returns a Promise.
280
+
`import()` takes the module name as argument and returns a Promise.
281
281
282
282
```js
283
283
functiononClick() {
284
-
System.import("./module").then(module=> {
284
+
import("./module").then(module=> {
285
285
module.default;
286
286
}).catch(err=> {
287
287
console.log("Chunk loading failed");
@@ -291,23 +291,25 @@ function onClick() {
291
291
292
292
Good news: Failure to load a chunk can be handled now because they are `Promise` based.
293
293
294
-
Caveat: `require.ensure` allows for easy chunk naming with the optional third argument, but `System.import` API doesn't offer that capability yet. If you want to keep that functionality, you can continue using `require.ensure`.
294
+
Caveat: `require.ensure` allows for easy chunk naming with the optional third argument, but `import` API doesn't offer that capability yet. If you want to keep that functionality, you can continue using `require.ensure`.
295
295
296
296
```javascript
297
297
require.ensure([], function(require) {
298
298
var foo =require("./module");
299
299
}, 'custom-chunk-name');
300
300
```
301
301
302
+
(Note on the deprecated `System.import`: Webpack's use of `System.import` didn't fit the proposed spec, so it was deprecated in [v2.1.0-beta.28](https://github.com/webpack/webpack/releases/tag/v2.1.0-beta.28) in favor of `import()`)
303
+
302
304
### Dynamic expressions
303
305
304
-
It's possible to pass a partial expression to `System.import`. This is handled similar to expressions in CommonJS (webpack creates a [context](https://webpack.github.io/docs/context.html) with all possible files).
306
+
It's possible to pass a partial expression to `import()`. This is handled similar to expressions in CommonJS (webpack creates a [context](https://webpack.github.io/docs/context.html) with all possible files).
305
307
306
-
`System.import` creates a separate chunk for each possible module.
308
+
`import()` creates a separate chunk for each possible module.
307
309
308
310
```js
309
311
functionroute(path, query) {
310
-
returnSystem.import("./routes/"+ path +"/route")
312
+
returnimport("./routes/"+ path +"/route")
311
313
.then(route=>newroute.Route(query));
312
314
}
313
315
// This creates a separate chunk for each possible route
0 commit comments