Theme source as a module

Hello everyone,

Here is an issue I have been struggling with figuring out for a while:

I have a theme that uses some NPM dependencies, and I would like to avoid having to commit the built files to the repo, but so far I have not found away that lets Hugo pull package.json from the theme when it is added as a module to run the build process on each theme instance.

For reference here is the theme repo:

And one theme instance (blog):

Currently, Hugo does not download files in root of the module repo, thus package.json is omitted.

I am not sure if I understand your issue. I would (without what I will write in the following paragraph) write a little shell script, that iterates through all the places and update dependencies and run build scripts and then go down to the repo root and run hugo.

But: Did anything with your issue change by using the new hugo npm command? I did not use it yet, but the documentation sounds like it might magically solve your issues. (v0.75.1 solves an issue with package.json, but I linked the 0.75.0 because it’s described there)

I was hopeful of 0.75 solving the issue, but with my trials I could not find a way that it does.

The issue is that when you add the module to hugo it only mounts the predefined asset directories, and not files in the root directory. Thus, my package.json does not get downloaded. Perhaps I can use ‘hugo npm’ if I put the package.json from the theme in a subfolder, but this is not ideal either

Hi, I have the same problem: how to use a theme as a module if a theme uses NPM?
Did you find any working solution @olafghanizadeh ?

Hugo has an experimental CLI command hugo mod npm pack I think that might be helpful? I did not try it yet though…

As far as I understand it creates a combined package.json in your root that collects all the package.json setups from further down the (module-)tree.