Roots Discourse

Scripts added to autoload don't get included

sage9
#1

Not seen any information in the documentation, but is there an additional process to include files the ‘scripts/autoload’ folder?

I’ve followed suit and name it with an underscrore, but whether I do that or not, files are not being included in main.js.

I have a script called megamenu.js.

Added to /assets/scripts/autoload/_megamenu.js

I then yarn run build. Compiled fine, but the content of the script don’t get included anywhere.

Do I need to add this somewhere else to get it included inside the /autoload/ folder?

If I add import “./autoload/_megamenu.js”; to main.js then it gets included, but is the right method? I have around 20 js files to include and wondered if thats the best way to include them all (separate imports for each)?

Any help would be appreciated.

0 Likes

#2

All you should have to do is place megamenu.js inside of scripts/autoload. Don’t name it _megamenu.js.
You shouldn’t have to manually import it as you mentioned.
Do you get any errors when you run yarn build:production?

0 Likes

#3

I’m having a similar issue, where the .js files in /autoload/ get included when I run yarn run build:production but not when during development with yarn run start

0 Likes