systemjs / builder

SystemJS build tool
MIT License
466 stars 122 forks source link

Dynamic import support #813

Open guybedford opened 7 years ago

guybedford commented 7 years ago

Support dynamic import syntax through the Babel compiler.

This should probably disable Rollup optimizations for that specific module as Rollup doesn't support dynamic imports.

Then this should also be added to the plugin ecosystem as well.

guybedford commented 7 years ago

First attempt in https://github.com/systemjs/builder/commit/772382744a4eb6e51b47c0865c21bcc2cafedcc6.

MrJoe commented 6 years ago

What level of support for dynamic import is currently supported? (If any)

For example I noticed the following somewhat works

import * as x from "somemodule";

// whatever some code here
// followed by a dynamic import later in the file:
import("othermodule").then(x => { /* dosomething */ });

the othermodule is transpiled to _context.import("othermodule").then ... however normalization of the module does not work. So it didn't became _content.import("npm:othermodule:0.0.0/lib.js").then...

IceCreamYou commented 6 years ago

Is any support for dynamic imports via System.import() planned, or only ES6 import() syntax?

cancio commented 6 years ago

Is there any support for dynamic imports via System.import() currently? In other words, when using the builder, in the final bundle am I supposed to see the modules that are dynamically imported?

ffflabs commented 6 years ago

Nope. Modules imported with System.import are not considered as dependencies of the script calling them.

Which is not necessarily bad specially if you import a huge library inside a función call.

javadbat commented 5 years ago

I'm trying to build react router that works with systemjs and webpack together and I need a dynamic import to do so. does anyone know any solution for that? my router currently work with systemjs "System.import" to publishing it on npm I need to make it work with webpack too is there a way I can define systemjs as a dependency and import it in my module?