Coder Social home page Coder Social logo

Comments (2)

bluewings avatar bluewings commented on June 9, 2024 2

@Gooseware
You can use pug-as-jsx-loader.
The loader supports inline templates and can store the pug files separately.

And if you use create-react-app, you can use pug-as-jsx-loader with cra-rewired without npm run eject.

https://github.com/bluewings/cra-rewired/tree/master/examples/pug-as-jsx-loader

App.pug

.App
  header.App-header
    img.App-logo(src='{logo}', alt='logo')
    p
      | Edit 
      code src/App.js
      |  and save to reload.
    a.App-link(href='https://reactjs.org', target='_blank', rel='noopener noreferrer')
      | Learn React

App.js

import template from './App.pug';

class App extends Component {
  render() {
    return template({
      // variables
      logo,
    });
  }
}

from babel-plugin-transform-react-pug.

ForbesLindesay avatar ForbesLindesay commented on June 9, 2024

This is not currently supported. It would require an update to https://github.com/pugjs/babel-plugin-transform-react-pug/blob/master/src/index.js to handle a call to pug.compileFile by resolving the file name, reading the file, then running a slight variation on:

          const ast = parsePug(src);
          const context = Context.create(this.file, path, interpolationRef);
          const transformed = ast.nodes.map(node => visitExpression(node, context));
          const expression = transformed.length === 1 ? transformed[0] : t.arrayExpression(transformed);

          context.variablesToDeclare.forEach(id => {
            path.scope.push({kind: 'let', id});
          });

          path.replaceWith(expression);

This is not trivial, and not on my current road map, but if someone wants to take a stab at it, I'll do my best to review the pull request.

from babel-plugin-transform-react-pug.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.