Compile static nunjucks files with brunch.
njk-brunch-static is a processor for html-brunch-static, a brunch plugin designed to handle static html files. njk-brunch-static can convert nunjucks files into static html files with html-brunch-static's support for layouts and partial views.
If you're looking for support for deprecated "jade" files, check out jade-brunch-static.
npm install --save-dev brunch-static html-brunch-static njk-brunch-static
"brunch-static": "x.y.z"to package.json
"html-brunch-static": "x.y.z"to package.json
"njk-brunch-static": "x.y.z"to package.json
- Alternatively, you may use the latest git version with:
Add njk-brunch-static to your list of html-brunch-static processors:
exports.config =...plugins:static:processors:require'html-brunch-static'processors:require'njk-brunch-static'fileMatch: 'source/views/home.njk': filenamereplace/static\.njk/'.html'
Most options passed to njk-brunch-static are passed, verbatim, to nunjucks, with the exception of:
fileMatch is an anymatch that is used to determine which files will be handled by this processor. As an anymatch, it may be a string with globs, a regex, or a function that takes a filename and returns true if it should be handled, or false otherwise. The default will match files that end in
(filename) => filename.replace(/static\.njk/, '.html'))
fileTransform converts the input filename into an html filename. It takes a filename as input and returns the new filename with the html extension. If you set the fileMatch property above, you'll probably need to set this option as well to ensure that your output files end with the html extension.
Context and Local Variables
The html-brunch-static's context will be exposed in your nunjucks files as local variables allowing you to use them in your template.