-
-
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: re-run build when config files are changed in watch mode #11962
base: main
Are you sure you want to change the base?
Conversation
9c603ec
to
f482dc5
Compare
I think we should make the In Vite 5, we can enable this by default. (We can add a TODO for that for now) |
f482dc5
to
1c1916b
Compare
1c1916b
to
9f8e407
Compare
Made some modifications
|
Feeling like we need to add some type test to prevent casual public API breaking 🤔. |
/** | ||
* Watch config files and restart the server when they changed. | ||
* When enabled, the build function will return `() => RollupWatcher` | ||
* This will be set to true by default and be removed in Vite 5. | ||
* @default false | ||
*/ | ||
watchConfig?: boolean |
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 was thinking we add this param to build()
directly since it only needs to be controlled programatically. That way it's easier to create the type overload too.
@@ -435,13 +443,17 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{ | |||
} | |||
} | |||
|
|||
let rollupWatcher: RollupWatcher |
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 think we need to use a weakmap of the builds resolvedConfig
to RollupWatcher
, so that multiple build watches don't conflict with this single variable.
'.env', | ||
'.env.*', |
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.
The env files needs to be resolved from config.envDir
too, instead of process.cwd()
with path.resolve
.
configFileChokidar.on('all', async () => { | ||
await Promise.all([watcher.close(), configFileChokidar.close()]) | ||
build(inlineConfig) | ||
}) |
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 it would be nice to log that we're restarting because of config change, similar to
vite/packages/vite/src/node/server/hmr.ts
Lines 59 to 66 in 7110ddf
// auto restart server | |
debugHmr(`[config change] ${colors.dim(shortFile)}`) | |
config.logger.info( | |
colors.green( | |
`${path.relative(process.cwd(), file)} changed, restarting server...`, | |
), | |
{ clear: true, timestamp: true }, | |
) |
With the current PR, I think it would break since it returns a function-type regardless if ecosystem-ci passes, so it would be nice to avoid that with overloads.
Yes that would be great too. We have a bit of types test currently at vite/packages/vite/package.json Line 61 in 7110ddf
|
Description
fix #11916
Additional context
I left a
TODO
in the returned watcher variable, when the build function is re-runed, thewatcher
will be not be valid anymore. We need to add something likegetWatcher: ()=> RollupWatcher
(will be a breaking change) or use a global watcher ref to hold the reference. I'm not sure which is the better solution so I left a TODO there for code review. Anyway, with this PR, we could make the build re-run in cli.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).