Concatenate 2 x JS Files to Inline Script

Hi All, - Is it possible to concatenate 2 x JS files into an in-line script.

I’ve tried something like this but I can’t seem to get it to work:

{{- resources.Get := slice (resources.Get "../assets/js/all-menu-functions.js") (resources.Get "../assets/js/home-js.js") | resources.Concat "assets/js/home.js" | minify }}
<script>{{ .Content | safeJS }}</script>
{{ end }}

Thanks

A method cannot be used as the name of a variable. Also in Hugo variables are prefixed with the dollar sign e.g. $var

Please have a better look at the Asset Bundling example in the Hugo Pipes chapter of the documentation.

Yes I took a look at that previously.

But how do I get this content:
{{ $plugins := resources.Get “js/plugins.js” }}
{{ $global := resources.Get “js/global.js” }}
{{ $js := slice $plugins $global | resources.Concat “js/bundle.js” }}

into a tag like this in the html

<script>
concatenated inline JS here
</script>

Thanks,

{{ $plugins := resources.Get “js/plugins.js” }}
{{ $global := resources.Get “js/global.js” }}
{{ $js := slice $plugins $global | resources.Concat “js/bundle.js” }}
<script>
{{ $js.Content | safeJS }}
</script>
6 Likes

Perfect! …Legend :slight_smile: - Thanks

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.