I’ve been using hugo modules in my theme for a while now to bring down my themes CSS framework (bulma). This worked great under libsass and the older version that I was using as I could just mount the sass folder in my assets path and @import away.
But now bulma is all about the @use and @forward so I installed dart sass and am attempting to migrate but I’ve hit a snag in that no matter what I try the ToCSS process can’t find the @use’d file. “Can’t find stylesheet to import.” is the error.
I’m about to give up and move it to be the responsibility of npm but I wondered if anyone has a different solution?
Looking closely at it, I remember my theme includes all it’s runtime files (bulma, viewerjs, fontawesome) using hugo modules. Is it just better to use npm for those? I like the way hugo pulls them all for you so you don’t have to faff with npm.
Without any sample config or code all I can say is “WHERE is ToCSS looking for @use’d files”? There are configuration options to add other folders than the location of your current processed file. includePaths in the docs.
Yeah, these work if I’m using the NPM route as the framework files exist under “node_modules/bulma” but when using hugo modules they exist in some nebulous virtual area that only really exists at build time.
I can @import from the mounted location with something like @import "../bulma/component/media" for example but that doesn’t work when you swap that for a @use.
That nebulous existing area exists in the confines of GoHugo too. So if your postcss says “includePaths is assets/some/folder” and your module mounts the files in “assets/some/folder” then postcss/tocss will find them if you refer to them from that “includePath root”.
Don’t get me wrong, but you are describing a Blackbox here and the cat is very alive for me. Show some example code with real existing paths and mounts and we might see where you are going wrong.
I have the experience that the “hardcore” version of ../../../../some/folder/from/root always works in uses and imports, so that might be your first attempt. Your initial SASS/SCSS file is the local path and everything from there is relative.
As long as you use sass and postcss from within Hugo all these mounts are “real” for the system… Not in VSCode, but that might be fixed with some more configuration that is not relevant for now.
ERROR TOCSS-DART: failed to transform "/sass/main.scss" (text/x-scss): "/Users/ME/Projects/Personal/site-hugo-theme/assets/sass/main.scss:1:0": Can't find stylesheet to import.
If I instead use an @import line like this:
@import "utilities"
in my main.scss file I get no error and a css file containing processed css - though it’s non-functional for my purposes as bulma is all sass modules now.
If I instead use an NPM version of Bulma and add a correct include path for that location it also works.
You mounted the folder sass of bulma to the folder assets/sass/bulma and then in the includePaths you told sass o use the folder sass in the mount sass/bulma resulting in assets/sass/bulma/sass/ for ToCss. BUT… it’s in bulma
so:
"includePaths" (slice "assets/sass/bulma")
might fix it. maybe use the debug function in sass to debug from within your styles…
But from what I see you double-mount your sass folder… as in assets/sass/bulma/sass/sass in the path ToCss is working with.
By the way, why do you mount it? I would add it via package.json and then use node_modules as includePaths and refer to the full path from there. That feels more portable, if you are already using package.json for your site.
I think that might be the way I go. I figured I’d use modules as it seem more “go” then having to ensure a working node environment. That said, because of my usage of PostCss I’m having to run a package.json anyway.
EDIT. Having given it a brief look I remember now that I also found it was a super simple way to just include files/assets such as images or fonts in the build - and that getting my scss to bring them in automatically just wasn’t working.
I’m assuming that has to go in the main site project as opposed to the theme module? Since putting it in the theme module (where I think makes the most sense) causes the whole thing to fall over
Yeah… I am myself working on a weird system to overcome this limitation. But until then put everything relevant into the root package.json Have a look at wireit, but that is very “offtopic” in regards to Hugo. You might be able to load npm scripts from packages “down” to the root package with that.
Ok, this is very definitely why I went down the route of using modules to bring 3rd party projects in. Having to spread stuff that is specifically theme related into the main site project is not really what I want to do.
When you install the Bulma Sass library using npm install or similar, its files exist in the OS file system. In this case the Dart Sass executable is able to resolve paths to directory index files as expected.
When you import the Bulma Sass library as a Hugo module, its files exist in Hugo’s virtual file system. In this case the Dart Sass executable is unable to resolve paths to directory index files because the files do not exist in the OS file system.
git clone --single-branch -b hugo-forum-topic-51528 https://github.com/jmooring/hugo-testing hugo-forum-topic-51528
cd hugo-forum-topic-51528
hugo server
I recently created a repo that repacks the official Bulma release as a Hugo module (Theme). There is no customization but wrapping the release files in a Hugo module
This is fantastic work! Thanks very much for your efforts!
This is interesting. But I’m still not getting it working using your module Do your instructions assume the bulma module is imported in the main site module or in another theme module?