html-tpl-loader

1.0.0 • Public • Published

Lodash html template for webpack

Build Status Dependency Status

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

Documentation: Using loaders

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

Build Status

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)

Package Sidebar

Install

npm i html-tpl-loader

Weekly Downloads

5

Version

1.0.0

License

MIT

Last publish

Collaborators

  • jantimon