-
Notifications
You must be signed in to change notification settings - Fork 33
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
Preserve Vite's default extensions #1157
Conversation
integration/unplugin/src/index.ts
Outdated
config.resolve.extensions ??= [ | ||
// Vite's DEFAULT_EXTENSIONs from | ||
// https://github.com/vitejs/vite/blob/main/packages/vite/src/node/constants.ts#L29 | ||
'.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json', |
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.
Could we import this from Vite if present or would it be too much of a hassle?
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.
It's not exported from Vite. I was thinking of submitting a Vite PR to expose it.
But there's also an issue of adding Vite as a dependency. Is there a nice way to copy the constant over with just a dev dependency? I guess I could do it in a build script without much trouble.
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.
I succeeded in getting this to work via import { DEFAULT_EXTENSIONS } from '../../../node_modules/vite/dist/node/constants.js'
, but sadly esbuild wouldn't treeshake that module, so it ended up adding a bunch of unnecessary code to the bundle.
To fix this, I've added a Node step to build.sh
that extracts the one constant we need to an also-checked-in file. Does that seem reasonable?
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.
Yes, that seems like a good solution.
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.
Another idea I had: we could put this in a prepare
script so it runs when getting dependencies but not when building, which would slightly speed up the dev cycle (I yarn build more often than yarn install). Not sure the time penalty is enough to bother though.
It turns out the default behavior of our Vite unplugin disables all of Vite's default resolve extensions, including e.g.
.jsx
which was breaking a project I have that uses external JSX libraries (written in Solid, so distributes.jsx
files).