underscore-loader
Webpack loader for pre-compiled Underscore/Lodash templates with HTML minification
- template is compliled with lodash.template
- template are minified by html-minifier
Installation
$ npm install --save underscore-loader lodash.escape
Important!!1
For webpack 1.x.x use version 2.0.0Options (defaults)
Webpack (2.x.x) config{
// ...
module: {
rules: [
{
test: /\.tpl$/,
loader: 'underscore-loader',
options: {
engine: 'var _ = { escape: require(\'lodash.escape\') };\n',
minifierOptions: { collapseInlineTagWhitespace: true }
}
}
]
}
// ..
}
engine
- for full
lodash
set it tovar _ = require(\'lodash\');
- for full
underscore
set it tovar _ = require(\'underscore\');
lodash.escape
is default, change it tolodash
,underscore
orsome-other-engine
minify
- default is
true
- uses html-minifier
minifierOptions
- minify options - html-minifier options
originalSource
- append original html in comment
templateOptions
- template options - lodash documentation
Setting template engine
- 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: ''
)