You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #553 Add JSX integration for Vue.js (Kocal)
This PR was squashed before being merged into the master branch (closes#553).
Discussion
----------
Add JSX integration for Vue.js
Will close#551.
Doc: symfony/symfony-docs#11346
This PR enable JSX support in Vue.js with the following code:
```js
Encore.enableVueLoader(() => {}, {
useJsx: true
});
```
I've added inline documentation and some tests for:
- `enableVueLoader()` behavior (and validation)
- Babel loader rules generation
- Functional test, with styles and scoped styles (using CSS Modules)
As proof of concept for styles, after adding `<link href="build/main.css" rel="stylesheet">` in generated `testing.html` file:

- Styles from `App.css`, `App.scss` and `App.less` are applied globally correctly
- Styles from `Hello.css` are applied correctly to `Hello.jsx` component only (`import styles from './Hello.css?module'`)
<details>
<summary>This is an example of generated `main.css` file</summary>
```css
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
#app {
display: flex;
color: #2c3e90; }
#app {
margin-top: 40px;
}
.h1_jKs9e, .h2_3H2pR {
font-weight: normal;
}
.ul_3us5c {
list-style-type: none;
padding: 0;
}
.li_3bINq {
display: inline-block;
margin: 0 10px;
}
.a_wKHXy {
color: #42b983;
}
```
</details>
---
Some notes for the documentation:
- Install `@vue/babel-preset-jsx` and `@babel/plugin-transform-react-jsx`
- If you need to use scoped styles, use [CSS Modules](https://github.com/css-modules/css-modules) like this:
```css
/* MyComponent.css */
.title { color: red }
```
```jsx
// MyComponent.jsx
import styles from './MyComponent.css';
export default {
name: 'MyComponent',
render() {
return (
<div class={styles.title}>
My component!
</div>
);
}
};
```
- Not only CSS is supported for CSS Modules, Sass, Less and Stylus are supported too
- If you need to require an image, `<img src="./assets/image.png">` will not work, you should require it yourself like `<img src={require("./assets.image.png")}/>`.
Commits
-------
9cabf9b Add JSX integration for Vue.js
0 commit comments