Which way is the correct way to include extra JS files in Sage 9?

Add the file to /assets/config.json

For example, here is what mine looks look

 "entry": {
        "main": [
            "./scripts/main.js",
            "./styles/main.scss"
        ],
        "customizer": [
            "./scripts/customizer.js"
        ],
        "story-creator": [
            "./scripts/story-creator.js"
        ]

    },

Where 'story-creator.js is the custom js file to be added.

Then yarn run build

And then enqueue the file from src/setup.php

I believe this is covered pretty well in the docs https://github.com/roots/docs/blob/sage-9/sage/theme-development-and-building.md

1 Like