Skip to content

Commit 56e2e5f

Browse files
authored
Changed System.import to import()
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()`.
1 parent 9ecab88 commit 56e2e5f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

content/guides/migrating.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,15 @@ require.ensure([], function(require) {
273273
});
274274
```
275275

276-
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.
277277

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.
279279

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.
281281

282282
``` js
283283
function onClick() {
284-
System.import("./module").then(module => {
284+
import("./module").then(module => {
285285
module.default;
286286
}).catch(err => {
287287
console.log("Chunk loading failed");
@@ -291,23 +291,25 @@ function onClick() {
291291

292292
Good news: Failure to load a chunk can be handled now because they are `Promise` based.
293293

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`.
295295

296296
```javascript
297297
require.ensure([], function(require) {
298298
var foo = require("./module");
299299
}, 'custom-chunk-name');
300300
```
301301

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+
302304
### Dynamic expressions
303305

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).
305307

306-
`System.import` creates a separate chunk for each possible module.
308+
`import()` creates a separate chunk for each possible module.
307309

308310
``` js
309311
function route(path, query) {
310-
return System.import("./routes/" + path + "/route")
312+
return import("./routes/" + path + "/route")
311313
.then(route => new route.Route(query));
312314
}
313315
// This creates a separate chunk for each possible route

0 commit comments

Comments
 (0)