-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Plugin-React: Allow user provided babel plugins to be applied to non-project files #16
Comments
I work with a monorepo, where I use a bit of Vite alias trickery to remap workspace packages to reference the uncompiled typescript files. This allows changes to be seen without recompiling, without any babel plugins defined. I spent a long time figuring out why my project wasn't working after upgrading plugin-react, but eventually stumbled upon the same issue you have. I think the change is an improvement, however I, like you, want to be able to continue to apply babel transforms to these files. |
If anyone wants to write tests for vitejs/vite#6202, we can get it merged! |
For anyone using a monorepo and the Currently, To fix this, you can setup the plugin to use your own babel config on top of theirs by using .vite.config.js: reactPlugin({
babel: {
configFile: true, // Tells @vitejs/plugin-react that there is a babel.config.js or babel.config.json to search for
rootMode: "upward", // Use this if you want a shared babel.config.json at the root of your monorepo
}
}), babel.config.json (example): {
"only": ["**/packages/**/src"],
"ignore": ["**/node_modules/**"],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
"@quickbaseoss/babel-plugin-styled-components-css-namespace",
["babel-plugin-styled-components", { "displayName": true, "fileName": false }]
]
} You can add babel.config.js files within each project, as well. |
Clear and concise description of the problem
At present we can provide extra
babel
plugins to the@vitejs/plugin-react
via itsbabel
option, e.g:For the most part this works fine. The plugins provided are applied to project files, where a project file is not a
node_module
and starts with theprojectRoot
(project root being the current working directory). This is defined hereThis is where I encounter an issue. I am using
pnpm
workspaces in my project and have a directory structure like:During development my workspace packages use
src/index.ts
for their main entry-point in theirpackage.json
. This means when a file is loaded it needs to be transpiled (byvite
in this case). In my case I am using@compiled/react
which requires itsbabel
plugin to be applied before using the component. Since my packages will be outside the project-root the
react-plugin
will not apply the user provided plugins to it.Suggested solution
Allow users to specify an
include
(or something similar) option which can be used to ensure that user provided plugins are still applied. For example, logic defined in the vite react plugin, could become:Then I could do something like:
The usage I'd ideally like to have seen is similar to how babel handles situations like this
Alternative
In my case I could pre-build my dependencies but this is not a great developer experience. Not aware of any other alternatives - but definitely open to suggestions.
My main goal in suggesting this change is so that I can make changes to workspace packages and see live reloads without needing to build the workspace package.
Additional context
Happy to pick this up myself and raise a PR for it.
Validations
The text was updated successfully, but these errors were encountered: