Change header color 🎲 🎲

Jake Paris

in Maine, in 2024

Getting NPM build scripts to run-on-save in SublimeText

Today I finally got my es2015 javascript to compile to es5 javascript automatically upon save.

First, I set up my project using npm. I setup the following dev dependencies:

  • babel-cli
  • babel-core
  • babel-preset-es2015

In the package.json file, I’ve got the following scripts setup

…
"scripts": {
    "build-js": "babel scripts.pre.js --out-file scripts.js",
    "build": "npm run build-js"
    …
  },
…

In SublimeText, I had to create a new build system Tools > Build System > New Build System…. That looks like this:

{
    "shell_cmd": "npm run build"
}

It’s worth noting that the build in that command matches the json key of the my build directive in the package.json file. If I wanted to run the build-js line, I would have used that term instead. I already have the SublimeOnSaveBuild plugin installed in SublimeText.

That’s basically it. I have this feeling that there was one little thing in there that also needed to happen (which I didn’t quite catch with my brain) because it sort of seemed like magic. Maybe I’ll do this again from the beginning and then update this post.