Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rework the
compositionAPI
option of the preset to support Vue…
… 2.7
- Loading branch information
Showing
3 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,43 @@ import babelSugarCompositionApiRenderInstance from '@vue/babel-sugar-composition | |
import babelSugarVModel from '@vue/babel-sugar-v-model' | ||
import babelSugarVOn from '@vue/babel-sugar-v-on' | ||
|
||
export default (_, { functional = true, injectH = true, vModel = true, vOn = true, compositionAPI = false } = {}) => { | ||
export default (_, { | ||
functional = true, | ||
injectH = true, | ||
vModel = true, | ||
vOn = true, | ||
compositionAPI = false | ||
} = {}) => { | ||
// compositionAPI: 'auto' | 'native' | 'plugin' | false | ||
// legacy: compositionAPI: true (equivalent to 'auto') | ||
// bonus: compositionAPI: 'naruto' (equivalent to 'native') | ||
let injectHPlugin = babelSugarInjectH | ||
let importSource = '@vue/composition-api' | ||
|
||
if (compositionAPI) { | ||
if (compositionAPI === 'native' || compositionAPI === 'naruto') { | ||
importSource = 'vue' | ||
} | ||
|
||
if (compositionAPI === 'auto' || compositionAPI === true) { | ||
try { | ||
const vueVersion = require('vue/package.json').version | ||
if (vueVersion.startsWith('2.7')) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sodatea
Author
Member
|
||
importSource = 'vue' | ||
} | ||
} catch (e) {} | ||
} | ||
|
||
injectHPlugin = [babelSugarCompositionApiInjectH, { importSource }] | ||
} | ||
|
||
return { | ||
plugins: [ | ||
functional && babelSugarFunctionalVue, | ||
injectH && (compositionAPI ? babelSugarCompositionApiInjectH : babelSugarInjectH), | ||
injectH && injectHPlugin, | ||
vModel && babelSugarVModel, | ||
vOn && babelSugarVOn, | ||
compositionAPI && babelSugarCompositionApiRenderInstance, | ||
compositionAPI && [babelSugarCompositionApiRenderInstance, { importSource }], | ||
babelPluginTransformVueJsx, | ||
].filter(Boolean), | ||
} | ||
|
@sodatea what if the vue version > 2.7?