-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix(plugin-react): apply babel.plugins
to project files only
#5255
Conversation
if (useAutomaticRuntime) { | ||
// By reverse-compiling "React.createElement" calls into JSX, | ||
// React elements provided by dependencies will also use the | ||
// automatic runtime! | ||
const [restoredAst, isCommonJS] = isNodeModules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A slight difference in behavior here:
- Linked packages will now have their
React.createElement
calls reverse-compiled into JSX, so they will also use the automatic JSX runtime.
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
const isJSX = extension.endsWith('x') | ||
const isNodeModules = id.includes('/node_modules/') | ||
const isProjectFile = | ||
!isNodeModules && (id[0] === '\0' || id.startsWith(projectRoot + '/')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a virtual module wants to avoid being transformed by Babel, it can include /node_modules/
in its module ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Working well in Hydrogen! Thank you!
Thanks for checking this out @jplhomer! Let's release a patch for vite 2.6 and plugin-react with these changes then |
The idea here is to avoid parsing
node_modules
whenever possible, since that can be expensive in larger projects.Here's the heuristic I'm using to skip parsing:
For global plugins, set
babel.configFile
to true and create ababel.config.js
file in your project root.Future
We could detect a
babel.config.js
file in your project root and enablebabel.configFile
option automatically.