Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iyonaga/nunjucks-render-loader
Nunjucks loader module for webpack
https://github.com/iyonaga/nunjucks-render-loader
nunjucks nunjucks-loader webpack webpack-loader
Last synced: 6 days ago
JSON representation
Nunjucks loader module for webpack
- Host: GitHub
- URL: https://github.com/iyonaga/nunjucks-render-loader
- Owner: iyonaga
- License: mit
- Created: 2018-10-14T16:02:33.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T07:08:45.000Z (almost 2 years ago)
- Last Synced: 2024-11-14T17:12:08.695Z (about 1 month ago)
- Topics: nunjucks, nunjucks-loader, webpack, webpack-loader
- Language: JavaScript
- Homepage:
- Size: 604 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nunjucks-render-loader
Nunjucks loader module for webpack
## Installation
```shell
npm install --save nunjucks-render-loader
```## Usage
### webpack.config.js
```js
module: {
rules: [
{
test: /\.njk$/,
use: {
loader: 'nunjucks-render-loader',
options: {
path: path.resolve(__dirname, 'src/views')
}
}
}
]
},plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: './index.njk'
})
]
```## Tips
- ### Passing variables using HTML Webpack Plugin
#### webpack.config.js
```js
module: {
rules: [
{
test: /\.njk$/,
use: {
loader: 'nunjucks-render-loader',
options: {
path: path.resolve(__dirname, 'src/views')
}
}
}
]
},plugins: [
new HtmlWebpackPlugin({
foo: 'bar',
filename: 'index.html',
template: './index.njk'
})
]
```#### index.njk
```html
<!DOCTYPE html>{% include "partials/_head.njk" %}
<%= htmlWebpackPlugin.options.foo %>
```
- ### Require images
```html
<!DOCTYPE html>{% include "partials/_head.njk" %}
```
## Options
- `path` - Relative path to templates. (default: process.cwd())- `context` - Data to pass to the template. (default: {})
- `envOptions` - These are options provided for nunjucks Environment. More info [here](https://mozilla.github.io/nunjucks/api.html#configure). (default: {})