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 a couple of features that distinguish it from the alternatives:
- It automatically finds all partials and requires them, which adds them into your webpack bundle.
- It adds a
templateName
to the compile template function which can be easier to pass around your application if needed.
As of version 2.5.1 this loader supports only Webpack 2 and up.
- By default, the loader no longer wraps the templates in a wrapping function that calls
dust.render
. In addition, thewrapperGenerator
option has been removed. It has been replaced by awrapOutput
option for backwards-compatibility. See below for details. - The default
dustAlias
has changed. See below for details.
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
.
If you've set up an alias for dustjs-linkedin
, you can use this option to instruct the loader to use the same alias.
Set preserveWhitespace: true
to disable whitespace trimming. By default DustJS trims all whitespace before compiling a template, enabling this option will prevent this.
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 wrapOutput: true
to turn on the defaultWrapperGenerator from above.
Set verbose: true
to see console logs from dust-loader-complete