Custom JavaScript in manifest.json and building out into a single file

OK, so I’ve been trying to compile custom JS included in my main.js. After pulling my hair out a little, I found this thread: Sage Gulp Jshint - Trouble passing plugins.

Long story short, I’ve got my custom scripts getting pulled in via the vendor attribute under main.js in manifest.json. It does get compiled out into the main.js file but it’s right at the bottom of the file. My intended setup was the all the vendor scripts would be included first (basically as dependencies) and then the functions that fire these scripts (which are written into the scripts/main.js file) would then come afterwards.

Ultimately, I’m trying to keep everything in one file rather than have a separate dependencies/scripts file. Is this against the intended workflow?

The way you are envisioning is correct. The ordering is definitely supposed to be

  1. Bower packages
  2. Vendor packages
  3. First-party code

If it is getting compiled like:

  1. Bower packages
  2. First-party code
  3. Vendor packages

Something is not working properly.

What does your main.js dependency in manifest.json look like?

Open up an interactive node console (type node in project directory in CLI) and then run:


And lemme know what it spits out.

I added more tests to confirm

Thanks for the reply.

My manifest file looks like this currently (I tried vendor before and after files in manifest.json):

  "dependencies": {
    "main.js": {
      "vendor": [
      "files": [
      "main": true
    "main.css": {
      "files": [
      "main": true
    "editor-style.css": {
      "files": [
    "jquery.js": {
      "bower": ["jquery"]
    "modernizr.js": {
      "bower": ["modernizr"]
  "config": {
    "devUrl": "http://xxxxxxx:8888"

The output from node is:

[ { type: 'js',
    name: 'main.js',
     [ '/Bitbucket/ckd-2015/wp-content/themes/sage/bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/transition.js',
       'assets/scripts/main.js' ] },
  { type: 'js',
    name: 'jquery.js',
    globs: [ '/Bitbucket/ckd-2015/wp-content/themes/sage/bower_components/jquery/dist/jquery.js' ] },
  { type: 'js',
    name: 'modernizr.js',
    globs: [ '/Bitbucket/ckd-2015/wp-content/themes/sage/bower_components/modernizr/modernizr.js' ] } ]

You’ll see there’s slick.js which I’ve added in manifest.json between the bootstrap and main.js files, which is the correct order.

I’ve just double checked my main.js file that gets output and it’s definitely in the order I described in my OP i.e. wrong. This obviously wont mean too much but the final main.js file is here: The main thing is you can see the Slick (slick.js) references all towards the end of the file if you do a find for slick.


I recognize the bottom of that pastebin as the UTIL object at the bottom of the stock main.js file. I don’t think it’s out of order.

Why don’t you comment out uglify in the gulpfile.jsand verify that anything is out of order.

I just ran this through a beautifier and it looks fine:

1 Like

OK, totally my bad.

I’ve included some additional JS files and everything worked as intended. Running it through the beautifier or commenting out uglify would certainly have been clever things to do!

Thanks for the help guys, big fan of Sage. This is actually a project I’m porting over from Roots to Sage to keep up with ongoing development. Learning a lot :smile:

1 Like


post must be 20 characters

Possibly related: