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.escape
For 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
lodash
set it tovar _ = require(\'lodash\');
- for full
underscore
set it tovar _ = require(\'underscore\');
lodash.escape
is default, change it tolodash
,lodash/escape
,underscore
orsome-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: ''
)