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',
fork icon9
star icon2
watch icon0

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")
fork icon2
star icon13
watch icon0

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
fork icon0
star icon1
watch icon0