Range over array for bundling assets


I’m trying to bundle a bunch of smaller javascript files to one combined file, using the method specified here.

But i was wondering, that instead of having each file as a single variable, as it can be cumbersome to maintain in a growing platform. So what i tried to do, was make an array of the paths to the files, and then i would like to range over that array to create that part resources.Get "path" dynamically.

In my config.toml i have this array:

    node = [
    project = [

And this is what i tried, but without luck in my layout file _scripts.html

{{ $scripts := slice range .Site.Params.js.project resources.Get . end | resources.Concat "dist/scripts.min.js" | resources.Minify }}
<script type="text/javascript" src="{{ $scripts.Permalink }}"></script>

I get the following error when doing a range like that: unexpected <range> in operand

Kind regards,


I don’t think you can inline range like that. Instead:

{{ $js := slice }}
{{ range .Site.Params.js }}
  {{ $js = $js | append (resources.Get .) }}
{{ end }}
{{ $scripts := $js | resources.Concat "dist/scripts.min.js" }}
1 Like

Thank you so much for helping. It works perfectly!

I’m just adding some more information to this thread that is very much related, if someone else stumbles upon it.

I was hoping that i could include files directly from my node_modules folder, unfortunately not.

In the meantime i’ve just included the files i needed in node_modules directly into my assets folder, and crossing my fingers that the above feature will be added at some point.