Nunjucks is a templating library by Mozilla. This Rollup plugin integrates these great features into an easy interface without having to set up all of your templates.
npm install --save-dev @amprew/rollup-plugin-nunjucks
To use this plugin we specify an input and output file for our template and pass it into the plugin section:
import NunjucksPlugin from '@amprew/rollup-plugin-nunjucks';
{
...,
plugins: [
...[other plugins],
NunjucksPlugin({
input: './src/index.html',
output: './dist/index.html',
vars: {
ENVIRONMENT: 'production',
some_other_view_variable: 'some value'
},
opts: {}
})
]
Type: string
Default: none
Note: This input
option is a path to the input nunjucks file. This path can either be an absolute or relative.
Type: string
Default: none
Note: This output
option is a path to the output nunjucks file. This path can either be an absolute or relative.
Type: Object
{[key: string]: any}
Default: {}
Note: This vars
option is where you can specify any variable that gets passed to your template.
Type: Object
{[key: string]: any}
Default: {}
Note: This opts
option is to be used for configuring different arguments which get passed to Nunjuck's configure
function https://mozilla.github.io/nunjucks/api.html#configure.
type Function
(parameter: Nunjucks environment)
Default: undefined
Usage:
{
input: './source.njk',
output: './dist.html',
preRenderEnvironment: (environment) => {
environment.addFilter('shorten', function (str, count) {
return str.slice(0, count || 5) + '...';
});
}
}
template:
A message for you: {{ message|shorten }}