vuejs / jsx-vue2

monorepo for Babel / Vue JSX related packages
https://jsx-vue2-playground.netlify.app/
1.47k stars 96 forks source link

feat(babel-preset-jsx): Make `importSource` API configurable #291

Closed emosheeep closed 1 year ago

emosheeep commented 1 year ago

I've encountered a situation that I need to make my lib compatible with both vue 2.6 and vue2.7 at the same time, so I used vue-demi. I should ensure that all of imports from vue should be redirected to vue-demi which makes vue-demi work, but the plugin @vitejs/plugin-vue2-jsx which used @vue/babel-preset-jsx inside can't pass some options to control the import source. It will auto inject import {h} from 'vue' statements to the build result, which doesn't meet my needs. So I create this PR to extend the abilities of this plugin, wish I can pass { compositionAPI: { importSource: 'vue-demi' } } to the @vitejs/plugin-vue2-jsx with using vite. Please take a code review, thanks!

emosheeep commented 1 year ago

@sodatea there is something needs to be reviewed, thanks!

dongnaebi commented 1 year ago

maybe add an enum is enough

compositionAPI: 'auto' | 'native' | 'plugin' | 'vue-demi' | false
emosheeep commented 1 year ago

maybe add an enum is enough

compositionAPI: 'auto' | 'native' | 'plugin' | 'vue-demi' | false

of course, I just thought it might be more expansive. Does this commit can be merged after doing some modify?

dongnaebi commented 1 year ago

I need this too, @sodatea any suggestion? it's very useful to library author

emosheeep commented 1 year ago

I made some changes, please review again, thanks!