rollup-plugin-wontache
v0.1.0
Published
Rollup plugin for bundling Mustache templates with the Wontache engine
Downloads
7
Maintainers
Readme
rollup-plugin-wontache
Rollup plugin for bundling Mustache templates with the Wontache engine
Quickstart
Your template (hello.mustache
):
Hello, {{name}}!
Your code, which uses the template (index.js
):
import hello from './hello.mustache';
console.log(hello({name: 'World'}));
Your rollup.config.js
:
import wontache from 'rollup-plugin-wontache';
export default {
input: './index.js',
plugins: [wontache()],
// ...
};
Options
import wontache from 'rollup-plugin-wontache';
// ...
wontache({
include: '**/*.mustache',
exclude: [],
precompile: false,
delimiters: ['{{', '}}'],
wontache: 'mustache',
})
include
Glob string, or array of glob strings — Default: '**/*.mustache'
Transform only modules of which the file name matches the given pattern(s). Patterns are matched against the absolute path on disk. An empty array will include everything.
exclude
Glob string, or array of glob strings — Default: []
Skip modules of which the file name matches the given pattern(s). Patterns are matched against the absolute path on disk. An empty array will skip nothing.
precompile
Boolean — Default: false
This option only controls an optimization. The transformed module will always export a compiled, ready-to-run template function, regardless of whether you pass true
or false
.
If false
, the compilation happens during initial loading of the transformed module. If true
, the compilation already happens while Rollup is performing the transform, so the transformed module does not need to perform this work anymore.
The optimization is off by default, because it also has a cost: the precompiled version of a template is always larger than the original template text. Leave it off to keep your bundle as small as possible. Try switching it on when you find that there is too much delay during initial loading of the bundle. If you are publishing a library that includes bundled templates, consider giving your users a choice between bundles with and without precompilation.
If you want the transformed module to export the template as a string, instead of as an already compiled function, use rollup-plugin-string
instead.
delimiters
Array of exactly two nonempty strings — Default: ['{{', '}}']
Override this to change the delimiters with which your templates will be parsed initially, until encountering Set Delimiter tags.
Your template with alternative delimiters:
Hello, [name]!
Your override in rollup.config.js
:
// somewhere in an input config
plugins: [
wontache({
delimiters: ['[', ']'],
}),
],
wontache
String with valid JavaScript variable name — Default: 'mustache'
The transformed module imports the Mustache engine from Wontache. The wontache
option lets you override the name by which it is imported.
Transformed module, as the plugin outputs it by default:
import mustache from 'wontache';
export default mustache(...);
Your override in rollup.config.js
:
// somewhere in an input config
plugins: [
wontache({
wontache: 'sideburns',
}),
],
Alternative transformed module:
import sideburns from 'wontache';
export default sideburns(...);