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

Add section documenting babel-plugin-react-pug usage #24

Open
ForbesLindesay opened this issue Jan 25, 2017 · 0 comments
Open

Add section documenting babel-plugin-react-pug usage #24

ForbesLindesay opened this issue Jan 25, 2017 · 0 comments

Comments

@ForbesLindesay
Copy link
Member

This page should look along the lines of:

react-pug

You can use pug to generate react templates. This is supported via a babel-plugin. To use it, you need the following two plugins in your .babelrc:

{
  "plugins": [
    "transform-react-pug",
    "transform-react-jsx"
  ]
}

You can install them via:

npm install babel-plugin-transform-react-pug babel-plugin-transform-react-jsx --save-dev

Usage

To use react-pug, you just declare a tagged template literal:

import React from 'react';
import ReactDOM from 'react-dom';

function HomePage() {
  return pug`
    div
      h1 Home Page
      p Some content
  `;
}

ReactDOM.render(
  pug`HomePage`,
  document.getElementById('container'),
);

babel-plugin-transform-react-pug will convert the pug code in template literals into JSX.

Editor Support

In brackets you just install the pug plugin. In atom, install language-babel and the pug plugin, then configure the template literal tag in langauge-pug (this needs documenting properly).

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

No branches or pull requests

1 participant