vitejs / vite-plugin-vue2-jsx

Vite plugin for Vue 2.7 JSX support
MIT License
58 stars 6 forks source link

How to enable 'decorator' syntax? #11

Closed GodOfGod closed 1 year ago

GodOfGod commented 1 year ago

I am upgrading vue from 2.5 to 2.7. Before this, I use vue-property-decorator in my project, and this error occured in the file which use vue-property-decorator and tsx.

Error detail:

[plugin:vite:vue2-jsx] unknown: Support for the experimental syntax 'decorators' isn't currently enabled (34:1):

Add @babel/plugin-proposal-decorators (https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-decorators) to the 'plugins' section of your Babel config to enable transformation. If you want to leave it as-is, add @babel/plugin-syntax-decorators (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-decorators) to the 'plugins' section to enable parsing.

GodOfGod commented 1 year ago

Can pass a babelPlugins option to vueJsx, like this

vueJsx({ babelPlugins: [ ['@babel/plugin-proposal-decorators', { legacy: true }], ['@babel/plugin-proposal-class-properties', { loose: true }], ], })