I am a theme creator and I created a theme usingPostCSS and tailwind. And according to my understanding, users of my theme may need to use npm to install all the components that tailwind needs.
But this will bring inconvenience to users. Especially for users who don’t have npm.
And for most users, they don’t need to modify the css file. If I can directly generate the css file and provide it to the user, they can save a lot of energy.
The way I think about it now is to add the final generated css file to the theme. Is there a best practice to solve this problem?
You would still need npm installed for that. What hugo mod npm pack does is that it looks through your modules and creates a consolidated package.json file with the dependencies.
To me it seems like you have to commit a built CSS file to your repo (but this will not work well with something like PurgeCSS).
One option would be to use a specific environment for those users who do not have npm and load Tailwind via CDN, but there are many downsides to that as well.
You can also just build the site in the cloud (Netlify or Github Actions) for instance.
My understanding (but I should be wrong) is that using modules plus both hugo mod npm pack plus hugo mod vendor will avoid to have npm installed for theme user (only needed for you, the creator).
hugo mod vendor saves the Hugo module locally in your site directory, it does not do any dependency management. If you are using PostCSS to build the CSS file of your theme, you would still need to have that installed (and other npm dependencies such as tailwind).
I am thinking about checking the generated css file first. If exists, I will just use this file and use PostCSS if it does not exist. I think this may solve the problem? And I am also wondering if it is a best practice for this case.
Do you mean the style.css_fingerprint.content and style.css_fingerprint.json?
I have commited those files. But if the user does not use npm install to install modules, user will get error like Error: Cannot find module 'xxx'. And my code to import css is like this:
I find that if I use useResourceCacheWhen = "always", it can perform well. But fallback does not.
In my understanding, fallback use cache when the build falls (do not have extended version, modules for PoatCSS, etc.)? But when I use fallback, I just get those normal errors like: Error: Cannot find module 'xxx' and it seems that the cache has not been used.