Search code examples
javascripthtmlnode.jsnpmnunjucks

Resolving nunjucks templates from NPM ( node modules )?


Looking for a way to get nunjucks imports / includes to resolve from the NPM node_modules folder.

For example suppose we have a package installed like this:

npm i -S @example/cards

We now want to import from it like this within a template:

{% import "@example/templates/birthday.html" as birthday %}

Thoughts?


Solution

  • This will do the trick, as pointed out by @Aikon Mogwai:

    nunjucks.configure('node_modules');
    

    I have it implemented in @superflycss/cli in case anyone wants a reference implementation.