babel-plugin-transform-react-templates

Babel plugin to register react templates with a global function

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
babel-plugin-transform-react-templates
0.1.03 years ago3 years agoMinified + gzip package size for babel-plugin-transform-react-templates in KB

Readme

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;
      }
    }
  ]
]