Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Frontend] Add section for using JSX with Vue.js #11346

Closed
wants to merge 3 commits into from
Closed

[Frontend] Add section for using JSX with Vue.js #11346

wants to merge 3 commits into from

Conversation

Kocal
Copy link
Contributor

@Kocal Kocal commented Apr 7, 2019

Hi :)

This PR add a new section for using JSX with Vue.js:

Encore.useVueLoader(() => {}, {
    useJsx: true
});

We should not merge it before symfony/webpack-encore#553 is merged.

@Kocal Kocal changed the base branch from master to 3.4 April 7, 2019 13:41
@wouterj wouterj added the Waiting Code Merge Docs for features pending to be merged label Apr 7, 2019
frontend/encore/vuejs.rst Outdated Show resolved Hide resolved
frontend/encore/vuejs.rst Outdated Show resolved Hide resolved
frontend/encore/vuejs.rst Outdated Show resolved Hide resolved
@Kocal
Copy link
Contributor Author

Kocal commented Apr 7, 2019

Thanks for the review!

frontend/encore/vuejs.rst Outdated Show resolved Hide resolved
frontend/encore/vuejs.rst Outdated Show resolved Hide resolved
frontend/encore/vuejs.rst Outdated Show resolved Hide resolved
frontend/encore/vuejs.rst Outdated Show resolved Hide resolved
frontend/encore/vuejs.rst Show resolved Hide resolved
frontend/encore/vuejs.rst Show resolved Hide resolved
weaverryan added a commit to symfony/webpack-encore that referenced this pull request Apr 10, 2019
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:
![Capture d’écran de 2019-04-07 13-03-38](https://user-images.githubusercontent.com/2103975/55682600-27105a80-5936-11e9-8eb9-704b71aa7b49.png)
- 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
@Kocal
Copy link
Contributor Author

Kocal commented Apr 10, 2019

Thanks, reviews have been applied! :)

@javiereguiluz javiereguiluz removed the Waiting Code Merge Docs for features pending to be merged label Apr 11, 2019
@javiereguiluz javiereguiluz added this to the 3.4 milestone Apr 11, 2019
@javiereguiluz
Copy link
Member

Hugo, thank you so much for contributing these docs. We're so lucky to have someone like you contributing to Encore and Symfony! Thanks 🙇

javiereguiluz added a commit that referenced this pull request Apr 11, 2019
This PR was squashed before being merged into the 3.4 branch (closes #11346).

Discussion
----------

[Frontend] Add section for using JSX with Vue.js

Hi :)

This PR add a new section for using JSX with Vue.js:
```js
Encore.useVueLoader(() => {}, {
    useJsx: true
});
```

We should not merge it before symfony/webpack-encore#553 is merged.

Commits
-------

916ad73 [Frontend] Add section for using JSX with Vue.js
@Kocal Kocal deleted the encore/vuejs-jsx branch April 11, 2019 09:12
@Kocal
Copy link
Contributor Author

Kocal commented Apr 11, 2019

It's a pleasure to contribute to Symfony ecosystem! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants