dust-template-loader

1.0.3 • Public • Published

dust loader for webpack

Compiles dust templates and exports the compiled functions, allowing for rendering of the templates in a browser environment. This version has option ?whitespacestrue to preserves whitespaces in compilted template.

Usage

Documentation: Using loaders

var template = require("dust-template?whitespacestrue!./template-file.dust");
// => returns template-file.dust compiled as template function with name "template-file" and preserved whitespaces (good for DEV environment)
 
or 
 
var template = require("dust-template!./template-file.dust");
// => returns template-file.dust compiled as template function with name "template-file" and without whitespaces (good for PRODUCTION environment)
 

Recommended config

var whiteSpaces = process.env.NODE_ENV != 'production' ? 'whitespacestrue' : 'nowhitespaces';
 
module.exports = {
  module: {
    loaders: [
     { test: /\.dust$/, loader: 'dust-loader?' + whiteSpaces},
    ]
  }
};

Then you only need to write: require("./template-name.dust")

Rendering a template

You will need to bundle the dust core in your pack in order to render the compiled templates. Use file name to render template.

require('./views/foo/template-name.tpl');
 
dust.render('template-name', context, function(err, result){
    // result holds the rendered HTML code
});

License

MIT (http://www.opensource.org/licenses/mit-license.php)

Readme

Keywords

none

Package Sidebar

Install

npm i dust-template-loader

Weekly Downloads

3

Version

1.0.3

License

MIT

Last publish

Collaborators

  • kurdin