html-tpl-loader
v1.0.0
Published
Underscore HTML Templates loader for webpack
Downloads
14
Maintainers
Readme
Lodash html template for webpack
Combination of the html-loader and the underscore-loader for webpack. Uses the _.template
function to extract assets.
Installation
npm install html-tpl-loader --save-dev
Usage
var template = require("html-tpl!./file.html");
// => returns the template function compiled with underscore (lodash) templating engine.
// And then use it somewhere in your code
template(data) // Pass object with data
Alternatively you can also define html-tpl in your webpack.config file:
{
module: {
loaders: [
{ test: "\.tpl.html$", loader: "html-tpl" },
]}
}
var template = require('./file.tpl.html');
The html-tpl loader allows you to minify the html before compiling by setting a loader query string
{
module: {
loaders: [
{ test: "\.tpl.html$", loader: "html-tpl?minimize=true" }
]
}
The html-tpl loader allows you to not to add lodash before compiling by setting a loader query string
{
module: {
loaders: [
{ test: "\.tpl.html$", loader: "html-tpl?lodash=false" }
]
}
The html-tpl loader allows you to configure lodash template settings by setting a loader query string
{
module: {
loaders: [
{ test: "\.tpl.html$", loader: "html-tpl?evaluate=\\{\\[([\\s\\S]+?)\\]\\}&interpolate=\\{\\{([\\s\\S]+?)\\}\\}" }
]
}
Tests
Run unit tests:
npm install
npm test
Demo
http://jantimon.github.io/html-tpl-loader/
License
MIT (http://www.opensource.org/licenses/mit-license.php)