rollup-plugin-wontache

0.1.0 • Public • Published

latest version on npm author: Julian Gonggrijp license text code hosted on GitLab changelog issue tracker on GitLab pipeline status

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 stringsDefault: '**/*.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 stringsDefault: []

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

BooleanDefault: 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 stringsDefault: ['{{', '}}']

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 nameDefault: '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(...);

Package Sidebar

Install

npm i rollup-plugin-wontache

Weekly Downloads

0

Version

0.1.0

License

BSD-3-Clause

Unpacked Size

9.13 kB

Total Files

5

Last publish

Collaborators

  • jgonggrijp