Hugo: Add IncludePaths config option

Created on 9 Jul 2018  ยท  6Comments  ยท  Source: gohugoio/hugo

I am importing the material-components-web library like this in my .scss file:

@import "node_modules/material-components-web/material-components-web";

It seems to find the library correctly in my node_modules folder which is in the root of my project. However, this imports sub-libraries that hugo can't find:

error: failed to transform resource: SCSS processing failed: file "/home/user/website/node_modules/material-components-web/material-components-web.scss", line 17, col 1: File to import not found or unreadable: @material/button/mdc-button.

The file node_modules/@material/button/mdc-button.scss exists, but can't be found.

The error message complains about this line in the library:

@import "@material/button/mdc-button";

It seems it doesn't know where to find the @material folder. This works fine with webpack though.

Enhancement

Most helpful comment

I will have to think a little before I add this.

The niceness of the current restrictions is that it plays nicely with themes; the override paths are obvious and installation is mostly straightforward. node_modules, on the other hand, is usually a dumping ground that I would not love to have in my Hugo project -- and certainly not inherit automatically from some theme I found on the internet. I know about NPM and version lock files etc., but that is kind of what I want to move away from, if I can.

All 6 comments

In general:

  • I have tested this with several SASS frameworks without any issue
  • This is powered by LibSASS so you should check their issue tracker

Because the @import relative path is relative to material-components-web.scss path.

node_modules/
โ”œโ”€โ”€ @material
โ”‚ย ย  โ”œโ”€โ”€ animation
โ”‚ย ย  โ”œโ”€โ”€ auto-init
โ”‚ย ย  โ”œโ”€โ”€ base
โ”‚ย ย  โ”œโ”€โ”€ button
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ mdc-button-scss
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ ...
โ”‚ย ย  โ”œโ”€โ”€ card
โ”‚ย ย  โ””โ”€โ”€ ...
โ”œโ”€โ”€ material-components-web
โ”‚ย ย  โ”œโ”€โ”€ material-components-web.scss
โ”‚ย ย  โ””โ”€โ”€ ...
โ”‚

you need to change all @import path from @material to ../@material

@import "@material/button/mdc-button";

to

@import "../@material/button/mdc-button";

i believe that @import using @material path is resolved by sass-loader as explained in it's documentation here
(P.S. I'm not quite understand npm and nodejs thing though)

May also be related to this discussion:

https://discourse.gohugo.io/t/hugo-0-43-tocss-include-path/12820/20

"node_modules" is not a known import in Hugo. Read the above discussion.

Thanks for pointing me to this thread. This sounds like the problem I am having as well. With the exception that it seems to find the initial material-components-web.scss file just fine, but not the one that is imported there like this:

@import "@material/button/mdc-button";

This is most likely, because the @material folder is inside node_modules which in turn is not part of the ImportPath.

@pamubay changing all the imports isn't feasible, because they are inside node_modules which is managed by npm. So changed there get overridden with each update.

Managing this SASS dependency with a git submodule instead also doesn't work, because the files there also use the strange @ syntax which isn't even part of their repository folder structure.

When trying to compile the SASS locally with

sass themes/test/static/css/styles.scss

it fails like hugo does. But if I add some import paths like so:

sass -I . -I ./node_modules/ themes/test/static/css/styles.scss

It works. So having a feature to provide several paths for a sassInputPath config option would totally solve my issue and make Hugo even more awesome! :)

I will have to think a little before I add this.

The niceness of the current restrictions is that it plays nicely with themes; the override paths are obvious and installation is mostly straightforward. node_modules, on the other hand, is usually a dumping ground that I would not love to have in my Hugo project -- and certainly not inherit automatically from some theme I found on the internet. I know about NPM and version lock files etc., but that is kind of what I want to move away from, if I can.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mumblecrunch picture mumblecrunch  ยท  3Comments

digitalcraftsman picture digitalcraftsman  ยท  3Comments

nikolas picture nikolas  ยท  3Comments

moorereason picture moorereason  ยท  3Comments

kaushalmodi picture kaushalmodi  ยท  3Comments