Environments

If you have different environments you intend to deploy to that need different settings, this is no problem. Just make a second app.js file, but stick the name of your environment between the app and the js, like this: app.production.js. Now, when you run spike with the environment option set to production (ex. spike compile -e production), it will merge your production config (with priority) into your normal app config.

So let's say you have an app config that looks like this:

// app.js
module.exports = {
  posthtml: (ctx) => {
    return {
      defaults: [
        jade({
          filename: ctx.resourcePath,
          apiUrl: 'http://localhost:3000/api/v1'
        })
      ]
    }
  }
}

If you wanted to update that API url to a real one for production, you could set up an app.production.js file that looks like this:

// app.production.js
module.exports = {
  posthtml: (ctx) => {
    return {
      defaults: [
        jade({
          filename: ctx.resourcePath,
          apiUrl: 'http://real-website.com/api/v1'
        })
      ]
    }
  }
}

Since the two configuration files are merged, you don't lose all your other settings from the app.js file, it just merges in any new ones from app.production.js. Very amaze!

You can change the environment by passing --env name or -e name to either the spike compile or spike watch commands. See the CLI docs for more info.