babel-plugin-transform-react-templates

0.1.0 • Public • Published

babel-plugin-transform-react-templates

Register react templates with a global function

Install

Using npm:

npm install --save-dev babel-plugin-transform-react-templates

or using yarn:

yarn add babel-plugin-transform-react-templates --dev

Usage

Code:

// src/reactTemplateRegister.js

export default register(template, component) {
  templates[template] = component;
}

export const templates = {};

With options:

plugins: [
  [
    'transform-react-templates',
    {
      includes: [
        // Any jsx file nested inside a templates folder
        '**/templates/**/*.jsx'
      ],
      importRegisterFunctionFromModule: 'src/reactTemplateRegister.js',
      registerFunctionName: 'register',
      registerTemplateName: (moduleId) => {
        // Use filename as template name
        return path.parse(moduleId).name;
      }
    }
  ]
]

Readme

Keywords

Package Sidebar

Install

npm i babel-plugin-transform-react-templates

Weekly Downloads

113

Version

0.1.0

License

MIT

Unpacked Size

9.45 kB

Total Files

8

Last publish

Collaborators

  • oliverfoster