Skip to content
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

Support dynamic import in vanilla template for Babel v7 #1931

Merged
merged 3 commits into from
Jul 15, 2019

Conversation

pshrmn
Copy link
Contributor

@pshrmn pshrmn commented May 19, 2019

What kind of change does this PR introduce?

This PR enables use of dynamic import() in the vanilla template.

Fixes #1930

What is the current behavior?

A syntax error occurs.

What is the new behavior?

import() works as expected.

Checklist:

  • Documentation
  • Tests
  • Ready to be merged
  • Added myself to contributors table

I split the way that the change is added based on how Parcel does it internally.

v7 should be ready, it simply uses parserOpts.

v6 could use some work. My "fix" uses a plugin, which is what Parcel does for Babel v6. Parcel creates a custom plugin that is essentially the same as babel-plugin-syntax-dynamic-import. That wasn't playing nicely when I tried to do the same, so I updated the babel.6.26.js module to support babel-plugin-syntax-dynamic-import. I don't like this solution, particularly because the babel.6.26.min.js module wasn't updated, but it wasn't immediately obvious where these static files get generated.

Edit: I realized why the custom plugin wasn't working. getDefaultCode serializes the return object, so the function is transformed into null. I think the best solution will be to use babel-plugin-syntax-dynamic-import provided I figure out how to generate the minified Babel 6 module.

@lbogdan
Copy link
Contributor

lbogdan commented May 19, 2019

@pshrmn Very nice!

Doesn't seem to be working with v6, though? http://pr1931.cs.lbogdan.tk/s/muddy-field-v05k2

@pshrmn
Copy link
Contributor Author

pshrmn commented May 19, 2019

@lbogdan I think that is because it is using the minified version, which I didn't fix.

@pshrmn
Copy link
Contributor Author

pshrmn commented May 19, 2019

Ideally I would prefer to get Babel 6 working without touching those static files, but if that is the best approach, I would rather not try manually editing the minified version. Are those modules generated by some external script?

@pshrmn
Copy link
Contributor Author

pshrmn commented May 20, 2019

I removed the Babel 6 support for now. Both static Babel files were added in #446, so I think that the builds must have happened externally.

@CompuIves
Copy link
Member

Ahh, good point! I think we can merge this one in the meantime. I think I got the other ones by building babel-standalone with webpack.

@pshrmn pshrmn changed the title Support dynamic import in vanilla template Support dynamic import in vanilla template for Babel v7 Jun 26, 2019
@pshrmn
Copy link
Contributor Author

pshrmn commented Jun 26, 2019

Does the PR build through cs.lbogdan.tk no longer work? I wanted to do a sanity check that this still works before pinging about getting it merged but I'm getting a 503 error.

@lbogdan
Copy link
Contributor

lbogdan commented Jun 26, 2019

Hey @pshrmn ,

We recently made some improvements to the PR building workflow, while moving it to a different domain, please push a new (empty) commit so that it will pick up and build this PR.

@lbogdan
Copy link
Contributor

lbogdan commented Jun 26, 2019

Or you can merge master, as there were a few changes in the meanwhile. 🙂

@pshrmn
Copy link
Contributor Author

pshrmn commented Jun 26, 2019

I think that this is fine to merge. I'm not sure why the integration test is failing; the failing sandbox (https://codesandbox.io/s/6w66jzw3mn) is a Preact starter while this PR only affects Parcel templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vanilla template does not support dynamic import
3 participants