-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
feat: support including files in node_modules #306
base: main
Are you sure you want to change the base?
feat: support including files in node_modules #306
Conversation
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.
This is good because it doesn't increase the number options, but this makes it a breaking change for people using the exclude option.
I've discussed with other team members and for now the consensus is to not add more option just this uncommon use case, so I'll wait for next major of the plugin, which will probably be at the same moment as Vite 6 end of May but could be sooner if there is a need like supporting React 19 or a new meta framework
For info we want Vite 6 support to take off quickly so that plugin author can quickly depend on the environment API, so we will sadly wait a bit more for this PR |
@ArnaudBarre We'd love to use this for Storybook's React Native Web Vite support, which involves |
Yeah the main reason is that will be a breaking change. And for now this was always considered very edge case need from Vite point of view. It was safe enough to drop the node_module exclusion in the SWC plugin because at the time it did not transform any JS file. Can you provide a example a lot of people will run into with Vite+RN? Is there a reason you want to use Babel in place of SWC? |
@ArnaudBarre hey, also working on Storybook's React Native Web Vite support. The reason we need babel is that the metro bundler only supports babel and so most libraries that rely on some transforms use babel to achieve that. Also metro will automatically transpile all files including node modules and so many libraries are shipped untranspiled. This means that when adding web support we have to transpile many libraries in node_modules to get things to work. There are some examples of getting swc to work with react native but its not the normal path and it would require special handling for some libraries. |
@ArnaudBarre OK took me a second to understand how it's a breaking change, but I see now! 🙀 We can work around this somehow, so no pressure. But please know that there's a somewhat meaty use case (we think). We'll share our workaround here once we figure something out for anybody else who's running into this. Thanks so much for your quick reply & for all your hard work maintaining the plugins!!! ❤️ |
The goal of this PR was also the be able to add HMR to node_modules, which is a particular use case. To solve your need of running Babel on node_modules, maybe having a separate plugin would be cleaner: Using https://www.npmjs.com/package/vite-plugin-babel import recat from "@vitejs/plugin-react";
import babel from "vite-plugin-babel"
export default defineConfig({
plugins: [
react(),
babel({ includes: ["/node_modules/"] }),
],
}) Sorry Jinjiang for the notifications! |
We need this feature too. We develop two separate products in different Git repositories. These products have common UI that we want to share. So we put this shared code into a separate package that is installed in both of the products. This shared package doesn't have its own bundler, as otherwise it would interfere with HMR. And everything works except babel-plugin-formatjs, which we need to run against the code in the shared package. But since the shared package lives in node_modules the formatjs plugin never gets executed and as a result we get runtime errors from FormatJS. |
Description
User can't customize exclude option to support hmr for files inside node_modules.
Additional context
#304
With this PR, the reproduction can be fixed by Vite config:
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).