@a8k/nunjucks-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 a8kNunjucksLoader from 'https://cdn.skypack.dev/@a8k/nunjucks-loader';
</script>

README

@a8k/nunjucks-loader

The original 'nunjucks-html-loader' not support relative search path and webpack4 has warning. So, I fork it

Usage

install

npm i -D @a8k/nunjucks-loader

webpack rules

const configureHtmlLoader = ({ mini, projectDir }) => {
  return {
    test: /\.(html|njk|nunjucks)$/,
    use: [
      {
        loader: resolve('html-loader'),
        options: {
          minimize: mini && env.NODE_ENV === PROD,
        },
      },
      {
        loader: resolve('@a8k/nunjucks-loader'),
        options: {
          // Other super important. This will be the base
          // directory in which webpack is going to find
          // the layout and any other file index.njk is calling.
          // default search path is current resource path
          searchPaths: ['./src', './src/pages', './src/assets'].map(i => path.join(projectDir, i)),
        },
      },
    ],
  };
};