@kontent-market/tpl-loader
v1.0.2
Published
Underscore HTML Templates loader for webpack
Downloads
9
Readme
Introduction
This is a modified package, the original is https://github.com/jantimon/html-tpl-loader.git
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 @kontent-market/tpl-loader --save-dev
Usage
var template = require('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: '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: "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: "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: "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)