-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
Support decorators in .vue
file.
#430
Comments
Considering it as a bug. Please provide a minimal reproduction to continue the issue. |
There is an error in browser console |
It could be related to Vite dev server, since it works on build mode |
This is because Vite's esbuild syntax transformation occurs before the Vue plugin, and esbuild does not recognize Vue SFC, so it is ignored. |
How about this going? |
issues: vitejs#430 More thoughts: So should we not hard-code loader:'ts' and target:'es2020; { target: 'esnext', // vitejs#430 Support decorators in .vue file. vitejs#430 // target can be overridden by esbuild config target ...options.devServer?.config.esbuild, loader: 'ts', sourcemap: options.sourceMap, }, Just for fault tolerance and compatibility considerations vite is the basic component of vite-plugin-vue. When vite-plugin-vue calls the transformWithEsbuild function provided by vite:esbuild in the vite project, should it be consistent with the parameters of vite:esbuild calling transformWithEsbuild, that is, esbuildTransformOptions, that is, options.devServer?.config.esbuild in the development environment transformWithEsbuild( resolvedCode, filename, options.devServer?.config.esbuild || {}, resolvedMap, ) Because the running results of vite in the development environment and the production environment should be consistent, it is also necessary to keep it consistent with the parameters passed in when vite:esbuild calls the transformWithEsbuild function This code will only be triggered in the development environment, so it is correct to use options.devServer?.config.esbuild
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 |
relate pr #222 |
Fixed via #444 |
It will automatically read Try copying the content from |
Related plugins
plugin-vue
plugin-vue-jsx
Description
In newest
npm create vue@latest
project, we could use decorators after set"experimentalDecorators": true
in standalone.ts
files. But it couldn't be transformed in.vue
files in<script lang="ts"></script>
.I advice to support decorators in
.vue
files directly or with"experimentalDecorators": true
.Suggested solution
Support decorators in
.vue
files.Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: