Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "When Using Webpack..." to "Getting Started" #1445

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,45 @@ to be changed. This makes it easy to use the same code in
development and production, while using precompiled templates in
production.

## When Using Webpack...

```
$ npm install html-bundler-webpack-plugin nunjucks --save-dev
```

The [HTML bundler plugin for Webpack](https://github.com/webdiscus/html-bundler-webpack-plugin) compiles [nunjucks templates](https://github.com/webdiscus/html-bundler-webpack-plugin#using-template-nunjucks) into static HTML files.

Configurate the _webpack.config.js_ for using nunjucks tempaltes:
```js
const HtmlBundlerPlugin = require('html-bundler-webpack-plugin');

module.exports = {
plugins: [
new HtmlBundlerPlugin({
entry: {
// define templates as entriypoints here, e.g.:
index: 'src/views/pages/index.njk', // output to dist/index.html
'news/sport': 'src/views/pages/news/sport/index.njk', // output to dist/news/sport.html
},
preprocessor: 'nunjucks', // use nunjucks templating engine
preprocessorOptions: {
// paths to templates
views: [
'src/views/includes',
'src/views/partials',
],
jinjaCompatibility: false, // installs support for Jinja compatibility, defaults 'false'
// define nunjucks options here, e.g.:
autoescape: true,
// ...
},
}),
],
};
```

For all available options, see the nunjucks [API configure](https://mozilla.github.io/nunjucks/api.html#configure).

## More Information

That's only the tip of the iceberg. See [API](api.html) for API docs
Expand Down