Skip to content

Document usage of import() for code splitting #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dmackerman opened this issue Jan 3, 2017 · 5 comments
Closed

Document usage of import() for code splitting #589

dmackerman opened this issue Jan 3, 2017 · 5 comments

Comments

@dmackerman
Copy link

dmackerman commented Jan 3, 2017

Instead of the deprecated System.import.

As requested by @TheLarkInn. 😄

@catamphetamine
Copy link

A follow-up
webpack/webpack#3777

The migration guide says:

If you want to use import with Babel, you'll need to install/add the dynamic-import syntax plugin while it's still Stage 3 to get around the parser error. When the proposal is added to the spec this won't be necessary anymore.

At the same time, seems that it has been added recently:
babel/babel#4944

I'm now running my project without that babel syntax plugin and it seems to work.
So maybe reflect that in the migration guide, that the syntax plugin is not needed for the newest babel (or that developers should update their babel, though I'm not sure which package exactly, I just reinstalled all node_modules from scratch and it worked).

@jouni-kantola
Copy link
Contributor

@halt-hammerzeit: I'm doing import() in this branch:
https://github.com/jouni-kantola/webpack-output-by-build-type/tree/webpack2

Without plugins: ["syntax-dynamic-import"] options to babel-loader I get:

ERROR in ./src/index.js
Module build failed: SyntaxError: Unexpected token (10:24)

   8 | // using babel polyfill adds quite a lot of overhead
   9 | async function bootstrap() {
> 10 |     const { a } = await import('./deps/module-a.js');
     |                         ^
  11 |     a();
  12 |
  13 |     const { b } = await import('./deps/module-b.js');

This tells me code splitting with import doesn't work without syntax-dynamic-import.

@catamphetamine
Copy link

@jouni-kantola Did you reinstall node_modules?

rm -rf node_modules
npm install

@jouni-kantola
Copy link
Contributor

jouni-kantola commented Jan 5, 2017

Can you give me an example of your code? If you try this in babel's REPL, it throws:
Dynamic import

@catamphetamine
Copy link

@jouni-kantola Ok, if you're positive that it throws then it throws.
I'm not that much into babel and webpack.
And my repo is huge
https://github.com/halt-hammerzeit/webapp

JoshAddington added a commit to shapiromatron/hawc that referenced this issue Jan 6, 2017
Deprecation notice was added with webpack/webpack.js.org#499.
Usage of synamic import documented at webpack/webpack.js.org#589
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants