Skip to content

fix: watch build mode infinite build #19922

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

Closed
wants to merge 1 commit into from

Conversation

btea
Copy link
Collaborator

@btea btea commented Apr 23, 2025

Description

When executing vite build -w, if build.outDir is an empty string, it will cause an infinite packaging loop.

@sapphi-red
Copy link
Member

Why does the rebuild trigger? If I remember correctly, rollup only runs the rebuild when an imported file is changed.

@btea
Copy link
Collaborator Author

btea commented Apr 25, 2025

When build.outDir is an empty string, the watch will monitor the file changes in the current project's root directory. Each build will add new build files or modify the index.html file, thus triggering a new build, and the cycle repeats.

@sapphi-red
Copy link
Member

I think the problem is that the output overwrites the watched file. If I change the output filename, it doesn't happen.
https://stackblitz.com/edit/vitejs-vite-6vjnefzs?file=vite.config.js,index.html,package.json&terminal=build:watch

Setting build.outDir: '' is technically fine and I think we shouldn't disallow doing so. I think it's better to fix the behaivor in rollup. For example, output a warning if the output overwrites a watched path.

@btea
Copy link
Collaborator Author

btea commented Apr 25, 2025

We do output warning messages. But if it is in watch mode, because it will be triggered repeatedly, it seems meaningless even if the warning message is output, so in this case, I think it is more reasonable to terminate the process.

image

Do you think it's ok to set output.dir to the default value of dist if it's an empty string?

@sapphi-red
Copy link
Member

We do output warning messages. But if it is in watch mode, because it will be triggered repeatedly, it seems meaningless even if the warning message is output, so in this case, I think it is more reasonable to terminate the process.

Rollup can skip the rebuild if the rebuild if the output overwrites the input. Or can even skip the output and show an error. Setting build.outDir: '' is technically fine and I think we shouldn't break that usage.

Do you think it's ok to set output.dir to the default value of dist if it's an empty string?

I don't think it's ok. Because setting build.outDir: '' is fine if you have a different input than index.html and have entryFileNames set so that it's output as a different filename.

@btea
Copy link
Collaborator Author

btea commented Apr 26, 2025

Rollup can skip the rebuild if the rebuild if the output overwrites the input. Or can even skip the output and show an error. Setting build.outDir: '' is technically fine and I think we shouldn't break that usage.

At present, it seems that the rebuild is not skipped. Is there any configuration required?

@sapphi-red
Copy link
Member

At present, it seems that the rebuild is not skipped. Is there any configuration required?

It's not implemented. I mean it's better to fix on rollup side as there's not enough information on Vite side to do so, and the fix would benefit users in rollup as well.

@btea
Copy link
Collaborator Author

btea commented Apr 26, 2025

Thanks for the detailed response. I will create an issue for rollup.

@btea btea closed this Apr 26, 2025
@btea btea deleted the fix/watch-build-mode branch April 26, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants