vitejs / vite-plugin-vue

Vite Vue Plugins
MIT License
468 stars 147 forks source link

Support decorators in `.vue` file. #430

Open ruojianll opened 1 month ago

ruojianll commented 1 month ago

Related plugins

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

sxzz commented 1 month ago

Considering it as a bug. Please provide a minimal reproduction to continue the issue. Thanks.

Why reproduction is required

ruojianll commented 1 month ago
  1. npm create vue@latest
  2. cd your-project
  3. npm install
  4. Set "experimentalDecorators": true in tsconfig.app.json
  5. npm run dev
  6. Change src/HomeView.vue's script block.
    
    <script setup lang="ts">
    import TheWelcome from '../components/TheWelcome.vue'

function deco(){ console.log('deco works') } @deco class MyClass{}



There is an error in browser console `Uncaught SyntaxError: Invalid or unexpected token`.
It should show `deco works`.
sxzz commented 1 month ago

It could be related to Vite dev server, since it works on build mode vite build.

sxzz commented 1 month ago

This is because Vite's esbuild syntax transformation occurs before the Vue plugin, and esbuild does not recognize Vue SFC, so it is ignored.

ruojianll commented 2 weeks ago

How about this going?