Add `--overwriteOutDir` options (default `true`) to `vite build`
Description
Hi Vite Team. Thanks for all your hard work!
I think it would be great if the build
command didn't clear out the outDir
and simply emitted files to it when it's in lib mode, similar to what Rollup and Webpack do.
Let me break this down with a scenario in lib mode:
tsc --declaration --emitDeclarationOnly && vite build
Initially, I use tsc
for type-checking and to emit type files to dist
. Then, when running vite build
, it ends up clearing the entire dist
before builds. This causes me to lose all my types.
I'm aware there are plugins that can generate type files during the vite build
. However, I believe maintaining control over the build process is important, where vite build
should only emit files to the outDir
without wiping its contents. Currently, the default behavior is to clear it out.
So, here's my proposal: could we introduce an --overwriteOutDir
option that defaults to true? This way, when --overwriteOutDir
is false, vite build
won't clear the outDir
, and will only emit files into it.
If you think this idea sounds okay, I would love to help implement it.
Thanks again!
Suggested solution
Add --overwriteOutDir
options (default true
) to vite build
Alternative
No response
Additional context
No response
Validations
-
Follow our Code of Conduct -
Read the Contributing Guidelines. -
Read the docs. -
Check that there isn't already an issue that request the same feature to avoid creating a duplicate.