question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow importing Nunjucks macros with a namespace without mounting 'node_modules'

See original GitHub issue

I’ve just moved from the beta to v1.0.0 of the Frontend and I am wondering why you moved from the @ namespace in npm?

I was setting my nunjucks path to the @govuk-frontend folder and then my import path would be, for example, frontend/components/error-summary/macro.njk. I liked this as it was clear where the macro was coming from and it kind of namespaced the govuk stuff, which allowed me to use the same naming conventions, like a components folder etc (and worked the same for SASS frontend/settings/_colours.scss to import the govuk one and then settings/_colours.scss for my project one)

To get around this for nunjucks I just made the include path node_modules so I can specify govuk-frontend/components/... this works fine except for my tests have now gone from ~2s to ~13s. I assume this is because of the vast amount of folders in node_modules, so does anyone have any solutions for this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
NickColleycommented, Sep 17, 2018

Hey Graham,

Sorry for the delay, we’ve spoken about this as a team.

We want to make this easier so you don’t have to do work around in your own code, but we think doing any of these suggestions will result in a breaking change.

So we’re going to assign this to the 3.0.0 release, let us know if this is blocking you as it may be a while before we do a 3.0.0 release.

Nick

2reactions
web-bertcommented, Jul 5, 2018

I think these:

@import "settings/all";
@import "helpers/all";
@import "tools/all";
@import "core/typography";
@import 'core/lists';
@import "objects/width-container";
@import "objects/form-group";
@import "overrides/typography";
@import "overrides/spacing";

Would be nicer like this:

@import "govuk-settings/all";
@import "govuk-helpers/all";
@import "govuk-tools/all";
@import "govuk-core/typography";
@import 'govuk-core/lists';
@import "govuk-objects/width-container";
@import "govuk-objects/form-group";
@import "govuk-overrides/typography";
@import "govuk-overrides/spacing";

Thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing a Nunjucks Macro? - Stack Overflow
I have a script that renders a nunjucks contact.html template that looks like this: let fs = require('fs'); let nj = require('nunjucks'); ...
Read more >
dgeni-packages | Yarn
Dgeni Packages. This repository contains a collection of Dgeni Packages that can be used by the Dgeni documentation generator to create documentation from ......
Read more >
nhsuk-frontend/CHANGELOG.md - UNPKG
nhsuk-frontend/CHANGELOG.md ; 754, Use the latest [List panel nunjucks macro arguments](https://github.com/nhsuk/nhsuk-frontend/tree/master/packages/components/ ...
Read more >
Rendered Examples | Herman Documentation - OddBird
Both Sass & Nunjucks examples allow you to import external partials: ... @example njk // {% import 'macros.njk' as macros %} // {{...
Read more >
list of all node.js modules created on June 24, 2013
=velrok 2012-08-30 07:39 1.0.4 http accept-language parser nodejs ... For `npm install ahr2` for Node and `pakmanager build` for Ender / Pakmanager.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found