2.1.3 • Published 2 months ago

nunjucks-async-loader v2.1.3

Weekly downloads
1,665
License
MIT
Repository
github
Last release
2 months ago

nunjucks-async-loader npm.io

Asynchronous loader templates nunjucks.

Supports ESM modules 👍

Why You Need?

nunjucks.FileSystemLoader loads templates synchronously. See this issue.

Installation

$ npm i nunjucks-async-loader

Usage

import express from 'express';
import nunjucks from 'nunjucks';
import { FileSystemAsyncLoader } from 'nunjucks-async-loader';

const app = express();
const isDev = app.get('env') === 'development';

const loader = new FileSystemAsyncLoader('views', {
    watch: isDev, // (default: false) reload templates when they are changed.
    noCache: isDev // (default: false) never use a cache and recompile templates each time.
});

const env = new nunjucks.Environment(loader);

env.express(app);


app.get('/', function(req, res) {
    res.render('index.html');
});

app.listen(3000);

TypeScript

If you're having trouble importing a module into TypeScript, try adding settings to tsconfig.json:

{
    "compilerOptions": {
      "esModuleInterop": true,
      "allowSyntheticDefaultImports": true
    }
  }

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm ci
$ npm test

License

MIT

2.1.3

2 months ago

2.1.2

11 months ago

2.1.1

11 months ago

2.1.0

11 months ago

2.0.1

11 months ago

2.0.0-0

1 year ago

2.0.0

1 year ago

1.1.5

4 years ago

1.1.4

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.1.2

8 years ago

0.1.0

8 years ago