Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simple-nunjucks-loader

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-nunjucks-loader

Webpack loader for Nunjucks

  • 1.0.0-alpha.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.7K
decreased by-3.14%
Maintainers
1
Weekly downloads
 
Created
Source

Nunjucks templates loader for Webpack

This Webpack loader compiles Nunjucks templates. html-webpack-plugin compatible.

Install

npm install --save-dev simple-nunjucks-loader

Usage

Loader didn't expose window.nunjucksPrecompiled that could break some installations, that use it directly.

This loader will precompile Nunjucks templates. It also includes Nunjunks (slim) runtime for browser.

Add loader to your webpack config as follows:

webpack.config.js

module.exports = {
    module: {
        rules: [
            {
                test: /\.njk$/,
                use: [
                    {
                        loader: 'simple-nunjucks-loader'
                    }
                ]
            }
        ]
    }
};

For using with html-webpack-plugin just add it to plugins array, all options from it would be available as htmlWebpackPlugin.options in Nunjucks template.

webpack.config.js

const HTMLWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    module: {
        rules: [
            {
                test: /\.njk$/,
                use: [
                    {
                        loader: 'simple-nunjucks-loader'
                    }
                ]
            }
        ]
    },
    
    plugins: [
        new HTMLWebpackPlugin({
            template: 'src/page.njk'
        })
    ]
};

Refer to html-webpack-plugin page for all available options.

How it works

Nunjunks bundle all precompiled templates to window.nunjucksPrecompiled, then loads them via custom loader from this global object.

Loader precompiles all templates in module closure, and pass it down to custom Nunjucks loader, that retrieve templates from closure.

Also Nunjucks didn't have dependency tree for precompiled templates, it cause precompilation on-demand and will break bundle. To workaround this issue, simple-nunjucks-loader doing some regexp-fu and precompile all required templates.

Options

Loader supports limited number of Nunjuncks options. It's doesn't support watch (it's not relate to webpack files watch), noCache, web settings and express.

All other options get passed to Nunjunks Environment during files loading.

Keywords

FAQs

Package last updated on 18 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc