-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
Dev server does not transpile script in .vue files (but it works in .ts ones) #31
Comments
Can also be reproduced with this chromium version (has devtools; grab chrome-win.zip): |
It's worth noting that I was having issues with transpilation working in dev mode at all, for which I had to explicitly add export default defineConfig({
// [...]
plugins: [vue()],
build: {
target: ["chrome102", "safari13"],
},
esbuild: {
target: ["chrome102", "safari13"]
},
// [...]
}); Because of that I was not sure if issue belongs to vite or this plugin here. These issues might even potentially be unrelated, I mention the above thing just now, because I forgot at that time I even did this, assuming it just made things work. |
vite-plugin-vue/packages/plugin-vue/src/main.ts Lines 223 to 232 in d32cf69
I think you should use the latest browser for developing, |
My case is a little bit special, because I develop for an embedded browser for a video game, which is a product based on a fixed version of WebKit which they rebase on top of latest version with some considerate delay (current version is based on mid-2019 WebKit, they plan to update to newer one within a couple of months). With that + the fact this kind of browser has custom JavaScript bindings for communication with the game engine, it'd be hard to test with an outside browser, as even developing mocks would not give the exact same experience behavior. And the thing is, it basically fully works, until it encounters some ES2020+ syntax like here.
I see, would it be possible to consider changing it? I'm not exactly sure what's the relationship here between the Vue plugin and Vite, but I know setting Or perhaps it's a Vite bug that it transpiles |
Vite transpiles Assume esbuild target is Then the code
If this is seem like a bug. Vue Plugin should follow Vite config. Vue Plugin use If retrieved esbuild target from Vite is < ES2020. Plugin should show warning even error message. I can't provide any approach for your case excepting take patch. It is hard-coded. @sapphi-red Sorry for pinging. Would you see it as a bug? |
When But when FYI this part was set by vitejs/vite#10207 to avoid transpiling |
In my case it seems the browser turns out to not be actually ES2020< (Safari 13), as I can confirm that manually editing vue plugin's .js file under node_modules to change In such case I think it would be reasonable to just use the |
@p0358 same issue and modify target inside node_modules/vite-plugin-vue fix my problem too. I also agree that specifying a too low target which breaks the bundle is not the concern of this lib. It is user's concern specifying target in the config.esbuild. vite-plugin-vue should respect the target in esbuild regradless of the risk that may break the bundling. As seen above, browser starting from 2018 already support import.meta, which is much earlier than the release of es2020. |
When I used the decorator function of ts, I also encountered a problem When I used the decorator in the dev environment of vite, an exception occurred, but it was normal in the build environment So I checked the differences between the dev and build environments I found that in the build environment, the target of esbuild can be replaced by esbuild:{target}, esbuildTransformOptions in vite.config.ts, while in the dev environment, it is hard-coded, target:esnext, and esbuildTransformOptions does not replace target:esnext Logic executed when vite:esbuild builds https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/esbuild.ts (238) vite-plugin-vue Logic executed in dev environment https://github.com/vitejs/vite-plugin-vue/blob/main/packages/plugin-vue/src/main.ts (253) This leads to inconsistency between dev environment and build environment, which I find strange vite is the basic component of vite-plugin-vue. In the vite project, when vite-plugin-vue calls the transformWithEsbuild function provided by vite:esbuild, the parameters passed in should be consistent with the parameters of transformWithEsbuild called by vite:esbuild itself when building. That is, esbuildTransformOptions should be used to replace and merge target:esnext And this code will only be triggered in the development environment, so options.devServer?.config.esbuild can be used This way, the results of dev environment and build environment can be consistent So I submitted a PR #444 |
Describe the bug
I set my build/esbuild target to something below ES2020 in order to support by target browser (~Safari 13, supports around ES2019, pre-ES2020). Then I can use newer syntax in .ts files just fine, but as soon as I use any new syntax in .vue SFC files (inside of
<script lang="ts">
, no matter ifsetup
or not), I get errors, because it's not properly transpiled.One example of such syntax is optional chaining operator, and as such adding a line like
will yield error like following:
Again, it works as expected if I use this inside of any .ts file, but fails inside of .vue.
Reproduction
https://github.com/p0358/vite-vue-transpilation-repro
Steps to reproduce
?.
to.
)Example old browser to test in: https://github.com/niutech/qt-ultralight-browser (note this one sadly has no dev tools, I can package a build based on the same browser with dev-tools if you want to test)
System Info
Used Package Manager
pnpm
Logs
Validations
The text was updated successfully, but these errors were encountered: