Open Lenni009 opened 5 months ago
What I expect: If I set
target
in mytsconfig.json
,build.target
should follow that ifbuild.target
is undefined. What is actually happening:target
intsconfig.json
has no effect onbuild.target
.build.target
must be explicitly set in order for the build to succeed.
Thanks for pointing it out! I stumbled into the same issue myself today!
I use create-vue to generate a sample project, which contains vite and typescript configuration files. I feel like I'm completely lost in the front-end build tools. Vite config file has build.target
, and the tsconfig file has configuration items such as module
and target.
, I can't figure out how the two work together.
Documentation is
Explain in Detail
I'm currently investigating why Vite doesn't use the
esnext
target for thevite build
command, even though it is set astarget
andmodule
intsconfig.json
.I had to set
build.target
toesnext
in order for the build to succeed.I expected that this would be pulled from
tsconfig.json
if it wasn't explicitly given in thevite.config.ts
.Vite's docs are not really helpful here.
https://vitejs.dev/guide/features#target:
tsconfig.json
file? In thevite.config.ts
file?dev
, notprod
. This should be clarified.esbuild.target
?tsconfig.json
?In the
warning
box, there's this:target
where? Intsconfig.json
or inbuild.target
?tsconfig.json
, or at least checks for its existance.Tl;dr: What I expect: If I set
target
in mytsconfig.json
,build.target
should follow that ifbuild.target
is undefined. What is actually happening:target
intsconfig.json
has no effect onbuild.target
.build.target
must be explicitly set in order for the build to succeed.Your Suggestion for Changes
Something I'm not quite sure on: Does
esbuild.target
always useesnext
if not specified otherwise, regardless of environment?The
target
environment is clearly different between dev and prod (dev targetingesnext
, while prod useses2020
) -> should also be specified in that section (it's already more or less written down in https://vitejs.dev/guide/#browser-support and https://vitejs.dev/guide/build.html#browser-compatibility)It should also be noted that
build.target
is not taken fromtsconfig.json
ifbuild.target
isundefined
andtarget
is defined intsconfig.json
.It was also noted in #13756 that there should be only one single point to define
target
, which should be in thetsconfig.json
. So maybe this should be made into a feature issue, since there's clearly demand for this feature.Reproduction
https://github.com/Lenni009/vite-build-target-issue
Steps to reproduce
npm i
npm run build
-> build fails
vite.config.ts
target
property-> Build succeeds -> default
build.target
does not matchtarget
intsconfig.json