0.0.4 • Published 8 years ago

multi-mustache-loader v0.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Multi Mustache loader for webpack

NPM version NPM downloads total NPM license Build Status bitHound Overalll Score Dependency Status devDependency Status

Compiles Mustache templates with Hogan and optionally html-minifier. Support both single template file and multi template file.

the multi template file should only write as below:

<script type="template/text" id="tmp-multi-a"></script>
<script type="template/text" id="tmp-multi-b"></script>

Install

$ npm i multi-mustache-loader

Usage

module: {
    loaders: [ {
        test: /\.html$/,
        loader: 'multi-mustache'
        // loader: 'multi-mustache?minify'
        // loader: 'multi-mustache?{ minify: { removeComments: false } }'
        // loader: 'multi-mustache?noShortcut'
    } ]
}

one file one template

template.html

<ul>
{{#user}}
<li>{{name}}</li>
{{/user}}
</ul>
var template = require('./template.html');
var html = template({ foo: 'bar' });

one file more than one template

multi-template.html

<script type="template/text" id="tmp-name">
	<span>{{name}}</span>
</script>
<script type="template/text" id="tmp-post">
	<span>{{post}}</span>
</script>
var template = require('./multi-template.html');
var htmlName = template['tmp-name']({ name: 'multi-mustache-loader' });
var htmlPost = template['tmp-post']({post:'hello multi-mustache-loader!'});

If noShortcut is passed, then Hogan compiled template is returned instead, so you can pass it as partial.

var template = require('./template.html');
var template2 = require('./template2.html');
var html = template({ foo: 'bar' }, {partial: template2});

Documentation: Using loaders.

License

MIT