babel-plugin-transform-react-templates
v0.1.0
Published
Babel plugin to register react templates with a global function
Downloads
369
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;
}
}
]
]