Importing JS from node packages

ug not a big fan of huge “npm installs” so I have spent a fair amount of time pondering on that question.

If you dependency and bundling requirements are simple (which I guess is a good goal to have), you can get far by wrapping your dependencies in Hugo Components, ref. an experiment I did last week:

Once these libs are mounted into your project (either directly or via a module path (see above)) they are managed by Hugo’s package manager, which is what NPM is dreaming to be when it grows up.

Once all of this matures I have some plans to create some “Hugo maintained” packages for what we/I consider useful libraries for Hugo.

We could imagine Hugo doing some NPM interaction in the future, but at the moment, for it to work with Hugo modules, you either need to mount the distribution on the library’s GitHub repo or maybe have your own GitHub repo with a node_modules and mount that into your project, as in https://github.com/bep/hugo-jslibs/blob/master/alpinejs/config.toml

2 Likes