@sky-foundry/nunjucks-html-loader

A webpack loader that takes nunjucks templates and returns raw html. It also works with webpack's watch command

Usage no npm install needed!

<script type="module">
  import skyFoundryNunjucksHtmlLoader from 'https://cdn.skypack.dev/@sky-foundry/nunjucks-html-loader';
</script>

README

SkyFoundry Nunjucks (Webpack) HTML Loader

Nunjucks template loader for Webpack to generate static HTML files.

NPM version Github stars

Setup

You should already have a webpack project setup and a webpack config file in your project.

HTML Webpack Plugin

You should first setup html-webpack-plugin with inject: 'body' and template: 'nunjucks-html-loader!./src/pages/index.njk' (your entry nunjucks template).

plugins: [
  new HtmlWebpackPlugin({
    inject: 'body',
    template: 'nunjucks-html-loader!./src/pages/index.njk',
  }),
]

Webpack Copy Plugin

For images and other assets, the CopyPlugin is best suited for this.

The recommended options are:

plugins: [
  // ... (html webpack plugin and others)
  new CopyPlugin([
    {
      from: '**/*.{jpg,png,gif,svg,woff,eot,ttf}',
      context: 'src',
    },
  ]),
]

TO-DO...