-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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: always bundle config file, fix config hmr #5779
Conversation
packages/vite/src/node/config.ts
Outdated
@@ -853,6 +853,8 @@ export async function loadConfigFromFile( | |||
if (!isTS && !isMjs) { | |||
// 1. try to directly require the module (assuming commonjs) | |||
try { | |||
const bundled = await bundleConfigFile(resolvedPath) | |||
dependencies = bundled.dependencies | |||
// clear cache in case of server restart | |||
delete require.cache[require.resolve(resolvedPath)] | |||
userConfig = require(resolvedPath) |
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 feel the deps collection should be executed after the success required otherwise if there are syntax errors in the config will throw the error message from esbuild first and be less DX friendly to me.
Meanwhile, note that for now only the cache of root config has been cleared on requiring, meaning even if you collect the deps for HMR, it will still require the old nest module cache, which will make this only a partial fix. I'd feel it's better to always bundle and exclude the config file for consistency. (/cc https://github.com/egoist/bundle-require)
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 the case, there will still be the problem of cache not being updated for nested dependencies. Therefore, the collection of dependencies is still needed in this way, but the configuration file is integrated into the bundle every time the dependency is updated. Does that mean so? (By the way, the dependency should be after require for DX, thanks for reminding)
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.
@antfu I'd like to always bundle and require the bundled code.That is to say all the code in the if branch will be removed.
if (!isTS && !isMjs){
// code
}
And i have tried in my pr branch, it solves the cache problem.The code in the pr has updated.
eab1d38
to
20f1309
Compare
Description
Fix #5780.In resolveConfig, using
dependencies
variable to record the deps that config file used, but if config file isjs
, the dependencies info will be lost.Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).