Asynchronous loader templates nunjucks
npm install nunjucks-async-loaderAsynchronous loader templates nunjucks.
Supports ESM modules 👍
nunjucks.FileSystemLoader loads templates synchronously.
See this issue.
``bash`
$ npm i nunjucks-async-loader
`typescript
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);
`
If you're having trouble importing a module into TypeScript, try adding settings to tsconfig.json:
`json`
{
"compilerOptions": {
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
}
To run the test suite, first install the dependencies, then run npm test:
`bash``
$ npm ci
$ npm test