Webpack loader for pre-compiled Underscore/Lodash templates with HTML minification
- templates are compliled with lodash.template
- templates are minified by html-minifier
$ npm install --save underscore-loader lodash.escapeFor webpack 1.x.x use version 2.0.0
Webpack (2.x.x) config
{
// ...
module: {
rules: [
{
test: /\.tpl$/,
loader: 'underscore-loader',
options: {
engine: 'var _ = { escape: require(\'lodash.escape\') };\n',
minifierOptions: { collapseInlineTagWhitespace: true }
}
}
]
}
// ..
}- set it to
var _ = { escape: require(\'lodash/escape\') }; - for full
lodashset it tovar _ = require(\'lodash\'); - for full
underscoreset it tovar _ = require(\'underscore\'); lodash.escapeis default, change it tolodash,lodash/escape,underscoreorsome-other-engine
- default is
true - uses html-minifier
- minify options - html-minifier options
- append original html in comment
- template options - lodash documentation
- set underscore/lodash/other-module dependency in
package.json - if you don't use any logic in your templates, you can pass empty string (
engine: '')