Skip to content

Commit

Permalink
fix(plugin-vue): Support decorators in .vue file.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alamhubb committed Sep 15, 2024
1 parent 6ea0ec5 commit 982ee0e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/plugin-vue/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 982ee0e

Please sign in to comment.