From 982ee0e1458600b0213e3e43d62d0e496c1619ad Mon Sep 17 00:00:00 2001 From: socialuni Date: Mon, 16 Sep 2024 04:02:12 +0800 Subject: [PATCH] fix(plugin-vue): Support decorators in .vue file. issues: https://github.com/vitejs/vite-plugin-vue/issues/430 More thoughts: So should we not hard-code loader:'ts' and target:'es2020; { target: 'esnext', // #430 Support decorators in .vue file. https://github.com/vitejs/vite-plugin-vue/issues/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 --- packages/plugin-vue/src/main.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index 826ff807..a2c8b9ad 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -249,8 +249,11 @@ export async function transformMain( resolvedCode, filename, { - loader: 'ts', target: 'esnext', + // #430 Support decorators in .vue file. https://github.com/vitejs/vite-plugin-vue/issues/430 + // target can be overridden by esbuild config target + ...options.devServer?.config.esbuild, + loader: 'ts', sourcemap: options.sourceMap, }, resolvedMap,