Skip to content

Commit bc6db9c

Browse files
committed
Add JSX support for Vue 3
1 parent 31fd329 commit bc6db9c

File tree

8 files changed

+101
-30
lines changed

8 files changed

+101
-30
lines changed

CHANGELOG.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
11
# CHANGELOG
22

3-
## v4.6.0
3+
## UNRELEASED
44

5-
* #1254 Increased minimum Node version to 20 (@weaverryan)
5+
* #1295 Add JSX support for Vue 3 (@Kocal)
66

7-
* #1253 Allow sass-loader 14 (@cedric-anne)
7+
Enabling JSX support for Vue 3 is done with the `Encore.enableVueLoader()`:
8+
```js
9+
Encore.enableVueLoader(() => {}, {
10+
useJsx: true,
11+
version: 3,
12+
});
13+
```
814

9-
* #1247 Allow only configuring a plugin (@gimler)
15+
If you don't have a custom Babel configuration, then you're all set!
16+
But if you do, you may need to adjust it
17+
to add [`@vue/babel-plugin-jsx`](https://github.com/vuejs/babel-plugin-jsx) plugin to your Babel configuration:
18+
```js
19+
// babel.config.js
20+
module.exports = {
21+
plugins: [
22+
'@vue/babel-plugin-jsx'
23+
]
24+
};
25+
```
1026

11-
## v4.5.0
1227

13-
* #1235 Dropping support for Node 14 (16 is new min) and allowing `svelte` 4 (@weaverryan)
28+
## [v4.6.1](https://github.com/symfony/webpack-encore/releases/tag/v4.6.1)
1429

15-
* #1185 Bump `babel-loader` from 8.2.5 to 9.1.2 (@dppanteon) - the
16-
[CHANGELOG for babel 9](https://github.com/babel/babel-loader/releases/tag/v9.0.0)
17-
does not list any breaking changes besides increasing the minimum Node version.
30+
* #1256 Re-adding node 18 support (@weaverryan)
1831

19-
* #1224 Allow fork-ts-checker-webpack-plugin ^8.0 and ^9.0 (@buffcode)
32+
## [v4.6.0](https://github.com/symfony/webpack-encore/releases/tag/v4.6.0)
33+
34+
* #1254 Increased minimum Node version to 20 (@weaverryan)
35+
36+
* #1253 Allow sass-loader 14 (@cedric-anne)
37+
38+
* #1247 Allow only configuring a plugin (@gimler)
2039

21-
## [v4.4.0](https://github.com/symfony/webpack-encore/releases/tag/v4.5.0)
40+
## [v4.5.0](https://github.com/symfony/webpack-encore/releases/tag/v4.5.0)
2241

2342
### Features
2443

fixtures/vuejs-jsx/main_v3.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createApp } from 'vue'
2+
import App from './App'
3+
4+
const app = createApp(App);
5+
6+
app.mount('#app');

lib/WebpackConfig.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -763,11 +763,6 @@ class WebpackConfig {
763763

764764
this.vueOptions[key] = vueOptions[key];
765765
}
766-
767-
// useJsx and vue 3 are not currently supported by Encore
768-
if (this.vueOptions.useJsx && this.vueOptions.version === 3) {
769-
throw new Error('Setting both "useJsx: true" and "version: 3" for enableVueLoader() is not currently supported. Please use version: 2 or disable useJsx.');
770-
}
771766
}
772767

773768
enableEslintPlugin(eslintPluginOptionsOrCallback = () => {}) {

lib/features.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ const features = {
124124
],
125125
description: 'use Vue with JSX support'
126126
},
127+
'vue3-jsx': {
128+
method: 'enableVueLoader()',
129+
packages: [
130+
{ name: '@vue/babel-plugin-jsx' },
131+
],
132+
description: 'use Vue with JSX support'
133+
},
127134
eslint_plugin: {
128135
method: 'enableEslintPlugin()',
129136
// eslint is needed so the end-user can do things

lib/loaders/babel.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,14 @@ module.exports = {
8888
}
8989

9090
if (webpackConfig.useVueLoader && webpackConfig.vueOptions.useJsx) {
91-
loaderFeatures.ensurePackagesExistAndAreCorrectVersion('vue-jsx');
92-
babelConfig.presets.push(require.resolve('@vue/babel-preset-jsx'));
91+
// TODO v5: Only keep the v3 code path
92+
if (webpackConfig.vueOptions.version === 3) {
93+
loaderFeatures.ensurePackagesExistAndAreCorrectVersion('vue3-jsx');
94+
babelConfig.plugins.push(require.resolve('@vue/babel-plugin-jsx'));
95+
} else {
96+
loaderFeatures.ensurePackagesExistAndAreCorrectVersion('vue-jsx');
97+
babelConfig.presets.push(require.resolve('@vue/babel-preset-jsx'));
98+
}
9399
}
94100

95101
babelConfig = applyOptionsCallback(webpackConfig.babelConfigurationCallback, babelConfig);

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"@symfony/mock-module": "file:fixtures/stimulus/mock-module",
6060
"@symfony/stimulus-bridge": "^3.0.0",
6161
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
62+
"@vue/babel-plugin-jsx": "^1.0.0",
6263
"@vue/babel-preset-jsx": "^1.0.0",
6364
"@vue/compiler-sfc": "^3.0.2",
6465
"autoprefixer": "^10.2.0",
@@ -110,6 +111,7 @@
110111
"@babel/preset-typescript": "^7.0.0",
111112
"@symfony/stimulus-bridge": "^3.0.0",
112113
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
114+
"@vue/babel-plugin-jsx": "^1.0.0",
113115
"@vue/babel-preset-jsx": "^1.0.0",
114116
"@vue/compiler-sfc": "^2.6 || ^3.0.2",
115117
"eslint": "^8.0.0",
@@ -157,6 +159,9 @@
157159
"@vue/babel-helper-vue-jsx-merge-props": {
158160
"optional": true
159161
},
162+
"@vue/babel-plugin-jsx": {
163+
"optional": true
164+
},
160165
"@vue/babel-preset-jsx": {
161166
"optional": true
162167
},

test/functional.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,25 +1707,20 @@ module.exports = {
17071707

17081708
const config = testSetup.createWebpackConfig(appDir, 'www/build', 'dev');
17091709

1710-
if (getVueVersion(config) === 3) {
1711-
// not supported for vue3 at this time
1712-
this.skip();
1713-
1714-
return;
1715-
}
1716-
17171710
config.enableSingleRuntimeChunk();
17181711
config.setPublicPath('/build');
17191712
config.addEntry('main', `./vuejs-jsx/main_v${getVueVersion(config)}`);
17201713
config.enableVueLoader(() => {}, {
17211714
useJsx: true,
1715+
version: getVueVersion(config),
17221716
});
17231717
config.enableSassLoader();
17241718
config.enableLessLoader();
17251719
config.configureBabel(function(config) {
1726-
expect(config.presets[0][0]).to.equal('@babel/preset-env');
1720+
// throw new Error(JSON.stringify(config));
1721+
expect(config.presets[0][0]).to.equal(require.resolve('@babel/preset-env'));
17271722
config.presets[0][1].targets = {
1728-
chrome: 52
1723+
chrome: 109
17291724
};
17301725
});
17311726

yarn.lock

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
dependencies:
161161
"@babel/types" "^7.23.0"
162162

163-
"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.22.15":
163+
"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.22.15", "@babel/helper-module-imports@~7.22.15":
164164
version "7.22.15"
165165
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.22.15.tgz#16146307acdc40cc00c3b2c647713076464bdbf0"
166166
integrity sha512-0pYVBnDKZO2fnSPCrgM/6WMc7eS20Fbok+0r88fp+YtWVLZrp4CkafFGIp+W0VKw4a22sgebPT99y+FDNMdP4w==
@@ -1542,6 +1542,39 @@
15421542
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.4.0.tgz#8d53a1e21347db8edbe54d339902583176de09f2"
15431543
integrity sha512-JkqXfCkUDp4PIlFdDQ0TdXoIejMtTHP67/pvxlgeY+u5k3LEdKuWZ3LK6xkxo52uDoABIVyRwqVkfLQJhk7VBA==
15441544

1545+
1546+
version "1.2.2"
1547+
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-transform-on/-/babel-helper-vue-transform-on-1.2.2.tgz#7f1f817a4f00ad531651a8d1d22e22d9e42807ef"
1548+
integrity sha512-nOttamHUR3YzdEqdM/XXDyCSdxMA9VizUKoroLX6yTyRtggzQMHXcmwh8a7ZErcJttIBIc9s68a1B8GZ+Dmvsw==
1549+
1550+
"@vue/babel-plugin-jsx@^1.0.0":
1551+
version "1.2.2"
1552+
resolved "https://registry.yarnpkg.com/@vue/babel-plugin-jsx/-/babel-plugin-jsx-1.2.2.tgz#eb426fb4660aa510bb8d188ff0ec140405a97d8a"
1553+
integrity sha512-nYTkZUVTu4nhP199UoORePsql0l+wj7v/oyQjtThUVhJl1U+6qHuoVhIvR3bf7eVKjbCK+Cs2AWd7mi9Mpz9rA==
1554+
dependencies:
1555+
"@babel/helper-module-imports" "~7.22.15"
1556+
"@babel/helper-plugin-utils" "^7.22.5"
1557+
"@babel/plugin-syntax-jsx" "^7.23.3"
1558+
"@babel/template" "^7.23.9"
1559+
"@babel/traverse" "^7.23.9"
1560+
"@babel/types" "^7.23.9"
1561+
"@vue/babel-helper-vue-transform-on" "1.2.2"
1562+
"@vue/babel-plugin-resolve-type" "1.2.2"
1563+
camelcase "^6.3.0"
1564+
html-tags "^3.3.1"
1565+
svg-tags "^1.0.0"
1566+
1567+
1568+
version "1.2.2"
1569+
resolved "https://registry.yarnpkg.com/@vue/babel-plugin-resolve-type/-/babel-plugin-resolve-type-1.2.2.tgz#66844898561da6449e0f4a261b0c875118e0707b"
1570+
integrity sha512-EntyroPwNg5IPVdUJupqs0CFzuf6lUrVvCspmv2J1FITLeGnUCuoGNNk78dgCusxEiYj6RMkTJflGSxk5aIC4A==
1571+
dependencies:
1572+
"@babel/code-frame" "^7.23.5"
1573+
"@babel/helper-module-imports" "~7.22.15"
1574+
"@babel/helper-plugin-utils" "^7.22.5"
1575+
"@babel/parser" "^7.23.9"
1576+
"@vue/compiler-sfc" "^3.4.15"
1577+
15451578
"@vue/babel-plugin-transform-vue-jsx@^1.4.0":
15461579
version "1.4.0"
15471580
resolved "https://registry.yarnpkg.com/@vue/babel-plugin-transform-vue-jsx/-/babel-plugin-transform-vue-jsx-1.4.0.tgz#4d4b3d46a39ea62b7467dd6e26ce47f7ceafb2fe"
@@ -1655,7 +1688,7 @@
16551688
"@vue/compiler-core" "3.4.38"
16561689
"@vue/shared" "3.4.38"
16571690

1658-
1691+
"@vue/[email protected]", "@vue/compiler-sfc@^3.4.15":
16591692
version "3.4.38"
16601693
resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.4.38.tgz#954c3f6777bbbcca28771ba59b795f12f76ef188"
16611694
integrity sha512-s5QfZ+9PzPh3T5H4hsQDJtI8x7zdJaew/dCGgqZ2630XdzaZ3AD8xGZfBqpT8oaD/p2eedd+pL8tD5vvt5ZYJQ==
@@ -2417,7 +2450,7 @@ camelcase@^5.0.0:
24172450
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
24182451
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==
24192452

2420-
camelcase@^6.0.0:
2453+
camelcase@^6.0.0, camelcase@^6.3.0:
24212454
version "6.3.0"
24222455
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a"
24232456
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==
@@ -4170,6 +4203,11 @@ html-tags@^2.0.0:
41704203
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-2.0.0.tgz#10b30a386085f43cede353cc8fa7cb0deeea668b"
41714204
integrity sha512-+Il6N8cCo2wB/Vd3gqy/8TZhTD3QvcVeQLCnZiGkGCH3JP28IgGAY41giccp2W4R3jfyJPAP318FQTa1yU7K7g==
41724205

4206+
html-tags@^3.3.1:
4207+
version "3.3.1"
4208+
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.3.1.tgz#a04026a18c882e4bba8a01a3d39cfe465d40b5ce"
4209+
integrity sha512-ztqyC3kLto0e9WbNp0aeP+M3kTt+nbaIveGmUxAtZa+8iFgKLUOD4YKM5j+f3QD89bra7UeumolZHKuOXnTmeQ==
4210+
41734211
htmlparser2@^6.1.0:
41744212
version "6.1.0"
41754213
resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-6.1.0.tgz#c4d762b6c3371a05dbe65e94ae43a9f845fb8fb7"

0 commit comments

Comments
 (0)