-
-
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
feat: use module runner to import the config #18637
base: main
Are you sure you want to change the base?
Conversation
fa4e6dd
to
3965409
Compare
Probably the test are failing because we support |
This looks similar to what Astro has been doing, which starts up the Vite server and Question: Does the module runner handle CJS config files well?
I'd honestly love if we start to not support them 😅 Separately from this PR, maybe we should start warning if we see them and suggest using |
Good catch! We can inject it with a different evaluator. |
Hm, module runner only supports ESM. Injecting To support a CJS config, we need to reimplement most of vite-node's "mix cjs-esm" code. Unless we forbid CJS altogether 😄 |
packages/vite/src/node/config.ts
Outdated
.map(([file]) => file) | ||
return { | ||
userConfig, | ||
dependencies, |
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.
Maybe here we can expose a close
callback that can free up mem?
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.
For now, I am just always closing the environment. I think if people want to use import files repeatedly, they can construct their own module runner. Or we can also expose something like createInlinedModuleRunner
that creates the environment all by itself
e546e04
to
31a84d9
Compare
I added |
Shouldn't using the module runner be opt-in instead? IIUC there's features like For the option name, it would be nice if it's |
It is opt-in, |
Oh didn't notice that, I thought it was |
Yeah, I agree. I just couldn't come up with a good name. I like |
Description
Very rough idea to use the module runner instead of
esbuild.build
. Some advantages:Benchmarking the
vitest.config.ts
file in the root:resolveConfig
to construct a simple resolved config (environment requires a config, we can construct a small one just for this environment since we control all private plugins)init
plugin containerrunner.import
AsyncFunction
ssrTransform
esbuild
Overall the new approach takes ~28-32ms and the old one takes ~14-22ms, but resolving the config is not a hot path fortunetly. We can also shave off 5-6ms if we provide a dummy config
This PR also adds an
inlineImport
experimental helper that creates a temporary environment with a module runner to import a single file.