Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pkolt/nunjucks-async-loader
Asynchronous loader templates nunjucks
https://github.com/pkolt/nunjucks-async-loader
Last synced: 18 days ago
JSON representation
Asynchronous loader templates nunjucks
- Host: GitHub
- URL: https://github.com/pkolt/nunjucks-async-loader
- Owner: pkolt
- License: mit
- Created: 2016-04-16T13:29:17.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-28T16:50:29.000Z (8 months ago)
- Last Synced: 2024-10-15T12:09:13.405Z (about 1 month ago)
- Language: TypeScript
- Size: 393 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# nunjucks-async-loader ![](https://github.com/pkolt/nunjucks-async-loader/workflows/main/badge.svg)
Asynchronous loader templates [nunjucks](http://mozilla.github.io/nunjucks/).
Supports ESM modules 👍
## Why You Need?
[nunjucks.FileSystemLoader](https://mozilla.github.io/nunjucks/api.html#filesystemloader) loads templates synchronously.
See this [issue](https://github.com/mozilla/nunjucks/issues/726).## Installation
```bash
$ npm i nunjucks-async-loader
```## Usage
```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);
```## TypeScript
If you're having trouble importing a module into TypeScript, try adding settings to `tsconfig.json`:
```json
{
"compilerOptions": {
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
}
```## Tests
To run the test suite, first install the dependencies, then run `npm test`:
```bash
$ npm ci
$ npm test
```## License
[MIT](LICENSE.md)