I’ve got hugo doing some heavy lifting for me and compiling multiple different javascript files on build, and it was previously working great until I started using Splide as a node package. Now it is only grabbing the one file.
In Javascript.HTML
partial:
{{- $jsNavigation := resources.Get "js/navigation.js" -}}
{{- $jsSlider := resources.Get "js/slider.js" -}}
{{- $scripts := slice $jsNavigation $jsSlider | resources.Concat "js/main.js" -}}
{{- $scripts = $scripts | js.Build -}}
{{- if hugo.IsProduction -}}
{{- $scripts = $scripts | minify -}}
{{- end -}}
<script type="text/javascript">{{- $scripts.Content | safeJS -}}</script>
Navigation.JS
function openNav() {
document.getElementById("mySidenav").style.width = "450px";
document.body.style.overflow = "hidden";
document.getElementById("overlay").style.display = "block"
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.body.style.overflow = "auto";
document.getElementById("overlay").style.display = "none"
}
Slider.JS
(Previously, this had some custom slider code, and it worked fine)
import Splide from "@splidejs/splide";
new Splide( '#image-carousel', {
type : 'fade',
autoplay : true,
rewind : true,
} ).mount();
Now, in either production or development, it no longer pulls in the navigation file. Rather, it’s just pulling in the Slider.JS
file.