How to use the precompile function from nunjucks
Find comprehensive JavaScript nunjucks.precompile code examples handpicked from public code repositorys.
8 9 10 11 12 13 14 15 16 17
}; } async precompile() { return new Promise((resolve, reject) => { const templates = nunjucks.precompile( path.join(__dirname, '../_includes/'), { include: [ 'preview.njk',
9
2
0
1 2 3 4 5 6 7 8 9 10 11
const fs = require('fs') let filenames = ['body-ch', 'body-en'] filenames.forEach(filename => { let env = new nunjucks.Environment(); let precompiledBody = nunjucks.precompile(filename + '.njk', { env: env }) fs.writeFile((filename + ".js"), precompiledBody, () => { console.log(filename, "done")
2
13
0
29 30 31 32 33 34 35 36 37 38
typeof envFn === "function" ? await envFn(new Environment()) : envFn; if (id.endsWith(".nunjucks.precompiled.js")) { // Generate the precompiled template module based on the ID const templatePath = id.slice(0, -".nunjucks.precompiled.js".length); const precompiledCode = precompile(templatePath, { ...precompileOptions, env: env, wrapper: (compiled, opts) => { const output = compiled
0
1
0
nunjucks.configure is the most popular function in nunjucks (144 examples)