Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 1ed8415

Browse files
committed
Webpack Encore: add JSX support for Vue
1 parent fb7521f commit 1ed8415

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed

assets/app/components/Button.jsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
export default {
2+
name: 'SymfonyAppTemplateButton',
3+
props: {
4+
color: {
5+
type: String,
6+
default: 'primary',
7+
},
8+
size: {
9+
type: String,
10+
default: 'sm',
11+
},
12+
disabled: {
13+
type: Boolean,
14+
default: false,
15+
},
16+
outline: {
17+
type: Boolean,
18+
default: false,
19+
},
20+
auto: {
21+
type: Boolean,
22+
default: false,
23+
},
24+
loading: {
25+
type: Boolean,
26+
default: false,
27+
},
28+
icon: {
29+
type: Boolean,
30+
default: false,
31+
},
32+
},
33+
methods: {
34+
genClasses() {
35+
return [
36+
'btn',
37+
`btn-${this.size}`,
38+
`btn-${this.color}`,
39+
this.loading && 'btn-loading',
40+
this.icon && 'btn-icon',
41+
this.disabled && 'disabled',
42+
this.outline && 'btn-outline',
43+
this.auto && 'btn-auto',
44+
];
45+
},
46+
},
47+
render() {
48+
return (
49+
<button disabled={this.disabled} class={this.genClasses()} on={this.$listeners} {...this.$attrs}>
50+
{this.loading ? (
51+
<div class="loading">
52+
<i class="fa fa-spinner-third fa-spin" />
53+
</div>
54+
) : (
55+
this.$slots.default
56+
)}
57+
</button>
58+
);
59+
},
60+
};

assets/pages/home/App.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
<template>
22
<div>
33
Hello world!
4+
5+
<SymfonyAppTemplateButton size="xs" outline>
6+
Je suis un bouton
7+
</SymfonyAppTemplateButton>
48
</div>
59
</template>
10+
11+
<script>
12+
import SymfonyAppTemplateButton from '@app/components/Button';
13+
14+
export default {
15+
name: 'App',
16+
components: {
17+
SymfonyAppTemplateButton,
18+
}
19+
}
20+
</script>

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
},
1010
"devDependencies": {
1111
"@symfony/webpack-encore": "^0.27.0",
12+
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
13+
"@vue/babel-preset-jsx": "^1.0.0",
1214
"autoprefixer": "^9.6.0",
1315
"core-js": "^3.0.0",
1416
"postcss-loader": "^3.0.0",

webpack.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ Encore
8181
},
8282
});
8383
}
84+
}, {
85+
useJsx: true
8486
})
8587

8688
// enables Sass/SCSS support

yarn.lock

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@
281281
dependencies:
282282
"@babel/helper-plugin-utils" "^7.0.0"
283283

284+
"@babel/plugin-syntax-jsx@^7.2.0":
285+
version "7.2.0"
286+
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.2.0.tgz#0b85a3b4bc7cdf4cc4b8bf236335b907ca22e7c7"
287+
integrity sha512-VyN4QANJkRW6lDBmENzRszvZf3/4AXaj9YR7GwrWeeN9tEBPuXbmDYVU9bYBN0D70zCWVwUy0HWq2553VCb6Hw==
288+
dependencies:
289+
"@babel/helper-plugin-utils" "^7.0.0"
290+
284291
"@babel/plugin-syntax-object-rest-spread@^7.2.0":
285292
version "7.2.0"
286293
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.2.0.tgz#3b7a3e733510c57e820b9142a6579ac8b0dfad2e"
@@ -718,6 +725,70 @@
718725
"@types/uglify-js" "*"
719726
source-map "^0.6.0"
720727

728+
"@vue/babel-helper-vue-jsx-merge-props@^1.0.0":
729+
version "1.0.0"
730+
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.0.0.tgz#048fe579958da408fb7a8b2a3ec050b50a661040"
731+
integrity sha512-6tyf5Cqm4m6v7buITuwS+jHzPlIPxbFzEhXR5JGZpbrvOcp1hiQKckd305/3C7C36wFekNTQSxAtgeM0j0yoUw==
732+
733+
"@vue/babel-plugin-transform-vue-jsx@^1.0.0":
734+
version "1.0.0"
735+
resolved "https://registry.yarnpkg.com/@vue/babel-plugin-transform-vue-jsx/-/babel-plugin-transform-vue-jsx-1.0.0.tgz#ebcbf39c312c94114c8c4f407ee4f6c97aa45432"
736+
integrity sha512-U+JNwVQSmaLKjO3lzCUC3cNXxprgezV1N+jOdqbP4xWNaqtWUCJnkjTVcgECM18A/AinDKPcUUeoyhU7yxUxXQ==
737+
dependencies:
738+
"@babel/helper-module-imports" "^7.0.0"
739+
"@babel/plugin-syntax-jsx" "^7.2.0"
740+
"@vue/babel-helper-vue-jsx-merge-props" "^1.0.0"
741+
html-tags "^2.0.0"
742+
lodash.kebabcase "^4.1.1"
743+
svg-tags "^1.0.0"
744+
745+
"@vue/babel-preset-jsx@^1.0.0":
746+
version "1.0.0"
747+
resolved "https://registry.yarnpkg.com/@vue/babel-preset-jsx/-/babel-preset-jsx-1.0.0.tgz#e515cd453a5a8ea6b0f30b2bb92f266d8ab4e9f5"
748+
integrity sha512-5CbDu/QHS+TtQNw5aYAffiMxBBB2Eo9+RJpS8X+6FJbdG5Rvc4TVipEqkrg0pJviWadNg7TEy0Uz4o7VNXeIZw==
749+
dependencies:
750+
"@vue/babel-helper-vue-jsx-merge-props" "^1.0.0"
751+
"@vue/babel-plugin-transform-vue-jsx" "^1.0.0"
752+
"@vue/babel-sugar-functional-vue" "^1.0.0"
753+
"@vue/babel-sugar-inject-h" "^1.0.0"
754+
"@vue/babel-sugar-v-model" "^1.0.0"
755+
"@vue/babel-sugar-v-on" "^1.0.0"
756+
757+
"@vue/babel-sugar-functional-vue@^1.0.0":
758+
version "1.0.0"
759+
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-functional-vue/-/babel-sugar-functional-vue-1.0.0.tgz#17e2c4ca27b74b244da3b923240ec91d10048cb3"
760+
integrity sha512-XE/jNaaorTuhWayCz+QClk5AB9OV5HzrwbzEC6sIUY0J60A28ONQKeTwxfidW42egOkqNH/UU6eE3KLfmiDj0Q==
761+
dependencies:
762+
"@babel/plugin-syntax-jsx" "^7.2.0"
763+
764+
"@vue/babel-sugar-inject-h@^1.0.0":
765+
version "1.0.0"
766+
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-inject-h/-/babel-sugar-inject-h-1.0.0.tgz#e5efb6c5b5b7988dc03831af6d133bf7bcde6347"
767+
integrity sha512-NxWU+DqtbZgfGvd25GPoFMj+rvyQ8ZA1pHj8vIeqRij+vx3sXoKkObjA9ulZunvWw5F6uG9xYy4ytpxab/X+Hg==
768+
dependencies:
769+
"@babel/plugin-syntax-jsx" "^7.2.0"
770+
771+
"@vue/babel-sugar-v-model@^1.0.0":
772+
version "1.0.0"
773+
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-v-model/-/babel-sugar-v-model-1.0.0.tgz#f4da56aa67f65a349bd2c269a95e72e601af4613"
774+
integrity sha512-Pfg2Al0io66P1eO6zUbRIgpyKCU2qTnumiE0lao/wA/uNdb7Dx5Tfd1W6tO5SsByETPnEs8i8+gawRIXX40rFw==
775+
dependencies:
776+
"@babel/plugin-syntax-jsx" "^7.2.0"
777+
"@vue/babel-helper-vue-jsx-merge-props" "^1.0.0"
778+
"@vue/babel-plugin-transform-vue-jsx" "^1.0.0"
779+
camelcase "^5.0.0"
780+
html-tags "^2.0.0"
781+
svg-tags "^1.0.0"
782+
783+
"@vue/babel-sugar-v-on@^1.0.0":
784+
version "1.0.0"
785+
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-v-on/-/babel-sugar-v-on-1.0.0.tgz#a633ee8fe205763e865b011246981b7f89668033"
786+
integrity sha512-2aqJaDLKdSSGlxZU+GjFERaSNUaa6DQreV+V/K4W/6Lxj8520/r1lChWEa/zuAoPD2Vhy0D2QrqqO+I0D6CkKw==
787+
dependencies:
788+
"@babel/plugin-syntax-jsx" "^7.2.0"
789+
"@vue/babel-plugin-transform-vue-jsx" "^1.0.0"
790+
camelcase "^5.0.0"
791+
721792
"@vue/component-compiler-utils@^2.5.1":
722793
version "2.6.0"
723794
resolved "https://registry.yarnpkg.com/@vue/component-compiler-utils/-/component-compiler-utils-2.6.0.tgz#aa46d2a6f7647440b0b8932434d22f12371e543b"
@@ -2976,6 +3047,11 @@ html-entities@^1.2.1:
29763047
resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-1.2.1.tgz#0df29351f0721163515dfb9e5543e5f6eed5162f"
29773048
integrity sha1-DfKTUfByEWNRXfueVUPl9u7VFi8=
29783049

3050+
html-tags@^2.0.0:
3051+
version "2.0.0"
3052+
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-2.0.0.tgz#10b30a386085f43cede353cc8fa7cb0deeea668b"
3053+
integrity sha1-ELMKOGCF9Dzt41PMj6fLDe7qZos=
3054+
29793055
htmlparser2@^3.3.0:
29803056
version "3.10.1"
29813057
resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.10.1.tgz#bd679dc3f59897b6a34bb10749c855bb53a9392f"
@@ -3568,6 +3644,11 @@ locate-path@^3.0.0:
35683644
p-locate "^3.0.0"
35693645
path-exists "^3.0.0"
35703646

3647+
lodash.kebabcase@^4.1.1:
3648+
version "4.1.1"
3649+
resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36"
3650+
integrity sha1-hImxyw0p/4gZXM7KRI/21swpXDY=
3651+
35713652
lodash.memoize@^4.1.2:
35723653
version "4.1.2"
35733654
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
@@ -5653,6 +5734,11 @@ supports-color@^6.1.0:
56535734
dependencies:
56545735
has-flag "^3.0.0"
56555736

5737+
svg-tags@^1.0.0:
5738+
version "1.0.0"
5739+
resolved "https://registry.yarnpkg.com/svg-tags/-/svg-tags-1.0.0.tgz#58f71cee3bd519b59d4b2a843b6c7de64ac04764"
5740+
integrity sha1-WPcc7jvVGbWdSyqEO2x95krAR2Q=
5741+
56565742
svgo@^1.0.0:
56575743
version "1.2.2"
56585744
resolved "https://registry.yarnpkg.com/svgo/-/svgo-1.2.2.tgz#0253d34eccf2aed4ad4f283e11ee75198f9d7316"

0 commit comments

Comments
 (0)