nunjucks-precompile-commonjs

0.0.1 • Public • Published

nunjucks precompile commonjs

Build Status

precompile

var fs = require('fs');
var nunjucks = require('nunjucks');
var wrapper = require('nunjucks-precompile-commonjs').wrapper;
 
var tmpl = nunjucks.precompile('path to views', {
    include: ['\\.html$'],
    wrapper: wrapper
});
 
fs.writeFileSync('path to output compiled-template.js', tmpl, 'utf8');

usage

var nunjucks = require('nunjucks');
var PrecompiledLoader = require('nunjucks-precompile-commonjs').Loader;
 
var tmpl = require('path to output compiled-template.js');
var loader = new PrecompiledLoader(tmpl);
// var originPrecompiledLoader = new nunjucks.PrecompiledLoader(tmpl);
var env = new nunjucks.Environment([loader]); // or: var env = new nunjucks.Environment([loader, originPrecompiledLoader]);
 
var templateContext = {xxx: 'xxx'}
 
console.log(env.render('template name', templateContext));

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i nunjucks-precompile-commonjs

    Weekly Downloads

    1

    Version

    0.0.1

    License

    MIT

    Last publish

    Collaborators

    • cdatou