[UPDATE]
It looks like the easiest way to do this is to just run the following with the below example, and hugo will auto-magically add the .min
(this is amazing, @bep. Thank you!). You can’t technically rename the file, but since it’s for only one script, asking for this feature seems like a very infrequent use case.
{{ $dsptmodal := resources.Get "/design-system-scripts/design-system-toggle-page-template-info.js" | minify | fingerprint }}
<script src="{{ $dsptmodal.RelPermalink }}"></script>
[PREVIOUS POST]
I love the new JS and SCSS features of Hugo’s native asset pipeline.
I don’t have issues concat, minify, etc with a slice
of multiple script files, but what about just minifying and renaming a single script file.
For example, I have a script at assets/design-system-scripts/design-system-toggle-page-template-info.js
that I would like to minify and fingerprint since it’s only included in one specific section:
{{$dsptmodal := resources.Get "/design-system-scripts/design-system-toggle-page-template-info.js" | resources.Concat "/js/ds-pt-modal.min.js" | minify | fingerprint }}
<script src="{{ $dsptmodal.RelPermalink }}"></script>
Obviously I’m not .Concat
'ing anything, so I think I’m looking for something closer to gulp.rename
in this case. The above does not work, but trying to play around similar to SCSS options, the following doesn’t work either:
{{ $dsptopts := (dict "targetPath" "/js/design-system-page-template-info.min.js" ) }}
{{ $dsptmodal := resources.Get "/design-system-scripts/design-system-toggle-page-template-info.js" | $dsptopts | minify | fingerprint }}
<script src="{{ $dsptmodal.RelPermalink }}"></script>
But still no luck and the following error in the terminal:
ERROR 2018/07/15 12:35:00 Error while rendering "page" in "page-templates/": template: _default/single.html:23:6: executing "_default/single.html" at <partial "site-script...>: error calling partial: template: partials/site-scripts.html:25:101: executing "partials/site-scripts.html" at <$dsptopts>: can't give argument to non-function $dsptopts
Total in 62 ms
ERROR 2018/07/15 12:35:00 Failed to rebuild site: logged 2 error(s)