A complete webpack loader for DustJS files.
dust-loader-complete is a webpack loader for DustJS files that compiles DustJS template files into their JavaScript template functions. It has two main advantages over the alternatives:
- Instead of returning the template function itself, it returns a wrapper function that can be called directly.
- It automatically finds all partials and requires them, which adds them into your webpack bundle.
- As of version 1.4.0, the returned wrapper function has a property
templateName
that holds the registered name of the template.
npm install --save-dev dust-loader-complete
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'
}
If you want to use NPM's dustjs-helpers module, you'll have to add the following alias:
alias: {
....
'dust.core': 'dustjs-linkedin'
}
dust-loader-complete offers several options to customize its behavior. Read the loader documentation to learn more about how to set loader options.
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
.
Customize the alias used for DustJS. Must match the alias set in the webpack configuration.
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 ); }";
}
Set verbose: true
to see console logs from dust-loader-complete