Hugo: Make --minify able to be set in config.toml

Created on 30 Aug 2018  路  12Comments  路  Source: gohugoio/hugo

It would be nice to not have to specify it on the command line, but in a config file.

Wish

Most helpful comment

Wouldn't this issue be resolved since 0.68.0?

All 12 comments

So, this was added as a "flag only" feature for a reason. The reason for that was that minification is expensive (takes time, CPU, memory), often the most time-consuming part of the site building. So you (or I) does not want it to *always be on.

So, any change to that behaviour needs better arguments than "it would be nice".

Sites with poorly designed CSS can show a difference between minimized and non-minimized versions. For example, https://github.com/baltimore-sun-data/voter-guide-2018/commit/c0d467c726cfd3024e8d4279d137d6b33ba3520a my election site never quite got the spacing around the buttons in our top nav worked out between the minimized and non-minimized versions.

We had another bug caused by a bad style being ignored by the browser but fixed by the minimizer. That was hard to debug.

So, this is a lesser issue now that we can have different configs for prod and dev, but my take on this is that:

  • There should be no functional/visual difference between a site with or without minify
  • If there is, it is a bug that should be fixed
  • If you run with minfy enabled all the time, those bugs will never be fixed and you will always run with the performance penalty
  • You can run both hugo --minify and hugo server --minfy so it is possible to get what you want today in a less declarative way.

One argument for providing minify in the config file is for automated builds. The setting belongs in the config file as a standard part of the build (if desired) in this situation.

Meanwhile forcing the user to have to remember to add --minify during local development testing is redundant and error prone when production testing is expecting --minify.

I have hugo run after I push to bare repo using a git hook. I have to tack on --minify:

while read oldrev newrev ref
do
    if [ "\${ref}" = refs/heads/master ];
    then
        echo "Master ref received:  Deploying ..."
        git --work-tree=${webroot} --git-dir=$home/frontend.git/ checkout -f
        ( cd ${webroot} && hugo --minify )
        ( cd ${theme_path} && npm i && npm run build )
        echo "Deployed!"
    fi
done

It wasn't an issue, but I could maybe see it being an issue for persons who do not have the ability to modify a git hook for whatever reason.

My memory is a little hazy at the moment, but I'm pretty sure it's now possible to say minify = true in config.toml -- can someone less lazy than me confirm?

I just tried in 0.55.6 and couldn't get minify = true to work.

You may be thinking of #5616, which would have added the feature but hasn't been merged yet.

I'll raise a new issue but removing --minify after a project has already been built with minification does not rebuild all the files. --minify messed up my JSON-LD and Google Analytics so need to rebuild all.

I think the JSON LD thing is probably https://github.com/golang/go/issues/33671.

Wouldn't this issue be resolved since 0.68.0?

Wouldn't this issue be resolved since 0.68.0?

Can confirm that it seems fixed. By adding the following to my config I no longer needed the --minify.

[minify]
  minifyOutput = true
Was this page helpful?
0 / 5 - 0 ratings