RajaJaganathan / dust-loader-complete

A complete webpack loader for DustJS files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dust-loader-complete

A complete webpack loader for DustJS files.

Overview

dust-loader-complete is a webpack loader for DustJS files that compiles DustJS template files into their JavaScript template functions. It has a couple of features that distinguish it from the alternatives:

  1. It automatically finds all partials and requires them, which adds them into your webpack bundle.
  2. It adds a templateName to the compile template function which can be easier to pass around your application if needed.

2.5.1 breaking changes

As of version 2.5.1 this loader supports only Webpack 2 and up.

3.0.0 breaking changes

  • By default, the loader no longer wraps the templates in a wrapping function that calls dust.render. In addition, the wrapperGenerator option has been removed. It has been replaced by a wrapOutput option for backwards-compatibility. See below for details.
  • The default dustAlias has changed. See below for details.

Installation

    npm install --save-dev dust-loader-complete

Usage

There are two changes you need to make to your webpack configuration in order to use dust-loader-complete.

First, add the following to the array of loaders (assuming your dust files are saved with a .dust extension):

    { test: /\.dust$/, loader: "dust-loader-complete" }

Second, provide an alias for the dustjs-linkedin module. dust-loader-complete writes a var dust = require( ) method at the top of every compiled template. It needs to know how to require the DustJS module. The default is to use the alias dustjs:

    alias: {
        dustjs: 'dustjs-linkedin'
    }

Note

If you want to use NPM's dustjs-helpers module, you'll have to add the following alias:

    alias: {
        ....
        'dust.core': 'dustjs-linkedin'
    }

Options

dust-loader-complete offers several options to customize its behavior. Read the loader documentation to learn more about how to set loader options.

root

Set a root path for your dust templates. This root will be removed from the beginning of the dust module path before it is turned into the template name via the namingFn.

dustAlias

If you've set up an alias for dustjs-linkedin, you can use this option to instruct the loader to use the same alias.

preserveWhitespace

Set preserveWhitespace: true to disable whitespace trimming. By default DustJS trims all whitespace before compiling a template, enabling this option will prevent this.

wrapperGenerator (prior to 3.0.0 only)

This option must be set via the "global" configuration object. What this means is that in your webpack configuration object, create a top-level object with the name `dust-loader-complete':

    {
        entry: '/path/to/entry.js',
        ....
        'dust-loader-complete': {
            wrapperGenerator: function ( name ) { .... }
        }
    }

This function generates the dust.render wrapper function. It receives a single parameter, the template name as a string, and it must return a string that when written out to the webpack JavaScript file will render the dust template. For example, the default function is

    function defaultWrapperGenerator( name ) {
      return "function( context, callback ) { dust.render( '" + name + "', context, callback ); }";
    }

wrapOutput

Set wrapOutput: true to turn on the defaultWrapperGenerator from above.

verbose

Set verbose: true to see console logs from dust-loader-complete

About

A complete webpack loader for DustJS files.

License:MIT License


Languages

Language:JavaScript 100.0%