gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
73.59k stars 7.39k forks source link

Allow PostProcess to write to disk when in server/memory mode #10568

Open bep opened 1 year ago

bep commented 1 year ago

See #10554

Any PostCSS post-processing via resources.PostProcess needs to work on files on disk. When running hugo server without options, everything is rendered and served from disk. You can do hugo server --renderToDisk, but that throws away the performance benefit of doing everything in memory just to handle a couple of CSS files.

We did, however, introduce a new flag recently:

--renderStaticToDisk         serve static files from disk and dynamic files from memory

I haven't tested it, but using that flag today should also work fine for the resources.PostProcess case. It will also write/serve files in /static to disk, but that's probably fine in most cases.

This issue is to track whether we can do better, possible detect the above situation and make resources.PostProcess use this hybrid file system, I'm not sure.

/cc @UtkarshVerma

UtkarshVerma commented 1 year ago

I tried the --renderStaticToDisk flag today, but it does not work for me. My use case is a bit hacky, so maybe you could chime in as well. Hugo does not have support for post-build tasks yet, and to avoid maintaining build recipes for each site, I wrote a custom PostCSS plugin in the theme to incorporate the build task.

Here's a short rundown:

While this is a bit hacky, it allows me to specify the plugin in the theme (not currently working on a module level: https://discourse.gohugo.io/t/how-to-make-postcss-recognize-hugo-module-imports/44633/2) and have all websites inherit the build recipe without needing to do anything extra.

In the context of this issue, I tried this, but in the server mode, I could not get the PDFs to generate with PostCSS in the public directory at all. It works with the non-server hugo command. Please let me know if you need further information.