babel-plugin-lodash-template-precompile
v1.0.0
Published
Babel plugin to precompile Lodash templates
Downloads
4
Maintainers
Readme
babel-plugin-lodash-template-precompile
Babel plugin to precompile Lodash templates
Install
$ npm i --save-dev babel-plugin-lodash-template-precompile
Example
Transforms
import template from 'lodash/template';
export default template`<div>hello {{ user }}!</div>`
to
export default function (data) {
var __t,
__p = '';
__p += '<div>hello ' + ((__t = user) == null ? '' : __t) + '!</div>';
return __p;
};
Usage
via .babelrc (Recommended)
{
"plugins": [["lodash-template-precompile", {"interpolate" : "\\{\\{(.+?)\\}\\}", "evaluate" : "\\[\\[(.+?)\\]\\]", "variable": "data"}]],
"presets": ["es2015"]
}
via Babel CLI
$ babel --plugins lodash-template-precompile --presets es2015 script.js
via Babel API
require('babel-core').transform('code', {
'plugins': [["lodash-template-precompile", {"interpolate" : "\\{\\{(.+?)\\}\\}", "evaluate" : "\\[\\[(.+?)\\]\\]", "variable": "data"}]],
'presets': ['es2015']
});
Note that setting variable
is required for use within strict mode