From 9471a38b851b944b5f61bb1cf2c742cc4a9d2e2f Mon Sep 17 00:00:00 2001 From: biodiscus Date: Mon, 24 Jul 2023 16:15:39 +0200 Subject: [PATCH] Add the information "Using with Webpack" into "Getting Started" --- docs/getting-started.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/getting-started.md b/docs/getting-started.md index 2e7088c91..aff530308 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -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