Skip to content

Commit 7131139

Browse files
committed
feat: use Vue 3 JSX plugin if Vue 3 is detected in the project
1 parent 7f56846 commit 7131139

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

packages/@vue/babel-preset-app/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Use this option when you have 3rd party dependencies that are not processed by B
8888

8989
- Default: `true`.
9090

91-
Set to `false` to disable JSX support. Or you can toggle [@vue/babel-preset-jsx](https://github.com/vuejs/jsx/tree/dev/packages/babel-preset-jsx) features here.
91+
Set to `false` to disable JSX support. Or you can toggle [@vue/babel-preset-jsx](https://github.com/vuejs/jsx/tree/dev/packages/babel-preset-jsx) (or [@ant-design-vue/babel-plugin-jsx](https://github.com/vueComponent/jsx) for Vue 3 projects) features here.
9292

9393
### loose
9494

packages/@vue/babel-preset-app/index.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,22 @@ module.exports = (context, options = {}) => {
112112

113113
// JSX
114114
if (options.jsx !== false) {
115-
presets.push([require('@vue/babel-preset-jsx'), typeof options.jsx === 'object' ? options.jsx : {}])
115+
let jsxOptions = {}
116+
if (typeof options.jsx === 'object') {
117+
jsxOptions = options.jsx
118+
}
119+
120+
let vueVersion = 2
121+
try {
122+
const Vue = require('vue')
123+
vueVersion = semver.major(Vue.version)
124+
} catch (e) {}
125+
126+
if (vueVersion === 2) {
127+
presets.push([require('@vue/babel-preset-jsx'), jsxOptions])
128+
} else if (vueVersion === 3) {
129+
plugins.push([require('@ant-design-vue/babel-plugin-jsx'), jsxOptions])
130+
}
116131
}
117132

118133
const runtimePath = path.dirname(require.resolve('@babel/runtime/package.json'))

packages/@vue/babel-preset-app/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"homepage": "https://github.com/vuejs/vue-cli/tree/dev/packages/@vue/babel-preset-app#readme",
2424
"dependencies": {
25+
"@ant-design-vue/babel-plugin-jsx": "^1.0.0-0",
2526
"@babel/core": "^7.9.6",
2627
"@babel/helper-compilation-targets": "^7.9.6",
2728
"@babel/helper-module-imports": "^7.8.3",
@@ -40,11 +41,15 @@
4041
},
4142
"peerDependencies": {
4243
"@babel/core": "*",
43-
"core-js": "^3"
44+
"core-js": "^3",
45+
"vue": "^2 || ^3.0.0-0"
4446
},
4547
"peerDependenciesMeta": {
4648
"core-js": {
4749
"optional": true
50+
},
51+
"vue": {
52+
"optional": true
4853
}
4954
}
5055
}

yarn.lock

+47
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@
99
dependencies:
1010
fswin "^2.17.1227"
1111

12+
"@ant-design-vue/babel-helper-vue-compatible-props@^1.0.0":
13+
version "1.0.0"
14+
resolved "https://registry.yarnpkg.com/@ant-design-vue/babel-helper-vue-compatible-props/-/babel-helper-vue-compatible-props-1.0.0.tgz#1cf8a267e04e7de4bd9207eb457bb40fbe96d69a"
15+
integrity sha512-BHOaxm9EJOqoBYWUMVFKwjgDkdqbGnY1KhQBJwTdrQGRDVjVXkxzyoDGJV52YAGgHQrdaSMWakwZIiTfncsNJQ==
16+
dependencies:
17+
"@ant-design-vue/babel-helper-vue-transform-on" "^1.0.1"
18+
19+
"@ant-design-vue/babel-helper-vue-transform-on@^1.0.0", "@ant-design-vue/babel-helper-vue-transform-on@^1.0.1":
20+
version "1.0.1"
21+
resolved "https://registry.yarnpkg.com/@ant-design-vue/babel-helper-vue-transform-on/-/babel-helper-vue-transform-on-1.0.1.tgz#d219d92f4e1fc5e7add211c347c7fa000518b623"
22+
integrity sha512-dOAPf/tCM2lCG8FhvOMFBaOdMElMEGhOoocMXEWvHW2l1KIex+UibDcq4bdBEJpDMLrnbNOqci9E7P2dARP6lg==
23+
24+
"@ant-design-vue/babel-plugin-jsx@^1.0.0-0":
25+
version "1.0.0-alpha.6"
26+
resolved "https://registry.yarnpkg.com/@ant-design-vue/babel-plugin-jsx/-/babel-plugin-jsx-1.0.0-alpha.6.tgz#bbb844b91c0032922f80e3d1f062177444077dae"
27+
integrity sha512-f95WdmKQkDGfSHHbqQ3xD5B/PPdg/DhHYlZE3UbIAN08e0YcjM+V1QlFAJYDfcefvsmLA/fGu/bIosBPZDZFWg==
28+
dependencies:
29+
"@ant-design-vue/babel-helper-vue-compatible-props" "^1.0.0"
30+
"@ant-design-vue/babel-helper-vue-transform-on" "^1.0.0"
31+
"@babel/helper-module-imports" "^7.0.0"
32+
"@babel/plugin-syntax-jsx" "^7.0.0"
33+
camelcase "^6.0.0"
34+
html-tags "^3.1.0"
35+
svg-tags "^1.0.0"
36+
1237
1338
version "0.11.3"
1439
resolved "https://registry.yarnpkg.com/@apollo/federation/-/federation-0.11.3.tgz#82252205c7f90fc69034f2a0073efa71aad52d0e"
@@ -516,6 +541,11 @@
516541
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.10.3.tgz#aac45cccf8bc1873b99a85f34bceef3beb5d3244"
517542
integrity sha512-j/+j8NAWUTxOtx4LKHybpSClxHoq6I91DQ/mKgAXn5oNUPIUiGppjPIX3TDtJWPrdfP9Kfl7e4fgVMiQR9VE/g==
518543

544+
"@babel/helper-plugin-utils@^7.10.4":
545+
version "7.10.4"
546+
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.10.4.tgz#2f75a831269d4f677de49986dff59927533cf375"
547+
integrity sha512-O4KCvQA6lLiMU9l2eawBPMf1xPP8xPfB3iEQw150hOVTqj/rfXz0ThTb4HEzqQfs2Bmo5Ay8BzxfzVtBrr9dVg==
548+
519549
"@babel/helper-regex@^7.10.1":
520550
version "7.10.1"
521551
resolved "https://registry.yarnpkg.com/@babel/helper-regex/-/helper-regex-7.10.1.tgz#021cf1a7ba99822f993222a001cc3fec83255b96"
@@ -952,6 +982,13 @@
952982
dependencies:
953983
"@babel/helper-plugin-utils" "^7.8.0"
954984

985+
"@babel/plugin-syntax-jsx@^7.0.0":
986+
version "7.10.4"
987+
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.10.4.tgz#39abaae3cbf710c4373d8429484e6ba21340166c"
988+
integrity sha512-KCg9mio9jwiARCB7WAcQ7Y1q+qicILjoK8LP/VkPkEKaf5dkaZZK1EcTe91a3JJlZ3qy6L5s9X52boEYi8DM9g==
989+
dependencies:
990+
"@babel/helper-plugin-utils" "^7.10.4"
991+
955992
"@babel/plugin-syntax-jsx@^7.2.0", "@babel/plugin-syntax-jsx@^7.8.3":
956993
version "7.8.3"
957994
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.8.3.tgz#521b06c83c40480f1e58b4fd33b92eceb1d6ea94"
@@ -6270,6 +6307,11 @@ camelcase@^5.0.0, camelcase@^5.2.0, camelcase@^5.3.1:
62706307
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
62716308
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==
62726309

6310+
camelcase@^6.0.0:
6311+
version "6.0.0"
6312+
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.0.0.tgz#5259f7c30e35e278f1bdc2a4d91230b37cad981e"
6313+
integrity sha512-8KMDF1Vz2gzOq54ONPJS65IvTUaB1cHJ2DMM7MbPmLZljDH1qpzzLsWdiN9pHh6qvkRVDTi/07+eNGch/oLU4w==
6314+
62736315
caniuse-api@^3.0.0:
62746316
version "3.0.0"
62756317
resolved "https://registry.yarnpkg.com/caniuse-api/-/caniuse-api-3.0.0.tgz#5e4d90e2274961d46291997df599e3ed008ee4c0"
@@ -10953,6 +10995,11 @@ html-tags@^2.0.0:
1095310995
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-2.0.0.tgz#10b30a386085f43cede353cc8fa7cb0deeea668b"
1095410996
integrity sha1-ELMKOGCF9Dzt41PMj6fLDe7qZos=
1095510997

10998+
html-tags@^3.1.0:
10999+
version "3.1.0"
11000+
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.1.0.tgz#7b5e6f7e665e9fb41f30007ed9e0d41e97fb2140"
11001+
integrity sha512-1qYz89hW3lFDEazhjW0yVAV87lw8lVkrJocr72XmBkMKsoSVJCQx3W8BXsC7hO2qAt8BoVjYjtAcZ9perqGnNg==
11002+
1095611003
html-webpack-plugin@^3.2.0:
1095711004
version "3.2.0"
1095811005
resolved "https://registry.yarnpkg.com/html-webpack-plugin/-/html-webpack-plugin-3.2.0.tgz#b01abbd723acaaa7b37b6af4492ebda03d9dd37b"

0 commit comments

Comments
 (0)