fix(plugin-react): apply babel.plugins to project files only#5255
Merged
patak-cat merged 5 commits intovitejs:mainfrom Nov 9, 2021
Merged
fix(plugin-react): apply babel.plugins to project files only#5255patak-cat merged 5 commits intovitejs:mainfrom
babel.plugins to project files only#5255patak-cat merged 5 commits intovitejs:mainfrom
Conversation
aleclarson
commented
Oct 11, 2021
| // By reverse-compiling "React.createElement" calls into JSX, | ||
| // React elements provided by dependencies will also use the | ||
| // automatic runtime! | ||
| const [restoredAst, isCommonJS] = isNodeModules |
Contributor
Author
There was a problem hiding this comment.
A slight difference in behavior here:
- Linked packages will now have their
React.createElementcalls reverse-compiled into JSX, so they will also use the automatic JSX runtime.
Collaborator
|
Just a heads up - this one will need a rebase |
1894895 to
b4b69cf
Compare
For global plugins, set `babel.configFile` to true and create a "babel.config.js" file in your project root.
b4b69cf to
bb7563c
Compare
aleclarson
commented
Nov 8, 2021
| const isJSX = extension.endsWith('x') | ||
| const isNodeModules = id.includes('/node_modules/') | ||
| const isProjectFile = | ||
| !isNodeModules && (id[0] === '\0' || id.startsWith(projectRoot + '/')) |
Contributor
Author
There was a problem hiding this comment.
If a virtual module wants to avoid being transformed by Babel, it can include /node_modules/ in its module ID.
patak-cat
previously approved these changes
Nov 8, 2021
patak-cat
approved these changes
Nov 8, 2021
9 tasks
jplhomer
approved these changes
Nov 9, 2021
Contributor
jplhomer
left a comment
There was a problem hiding this comment.
👍 Working well in Hydrogen! Thank you!
Member
|
Thanks for checking this out @jplhomer! Let's release a patch for vite 2.6 and plugin-react with these changes then |
patak-cat
pushed a commit
that referenced
this pull request
Nov 9, 2021
9 tasks
aleclarson
added a commit
to aleclarson/vite
that referenced
this pull request
Feb 3, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The idea here is to avoid parsing
node_moduleswhenever possible, since that can be expensive in larger projects.Here's the heuristic I'm using to skip parsing:
For global plugins, set
babel.configFileto true and create ababel.config.jsfile in your project root.Future
We could detect a
babel.config.jsfile in your project root and enablebabel.configFileoption automatically.