Target to a custom Mode in Vue CLI

Posted on December 3, 2019

Just a reminder and a TIL about customize the development setup of a Vue app with the CLI.

If you need to create a new custom Mode (other than 'staging', 'test' and 'production'), here the tip:

  • create a new .env.mymode file (where .mymode is the name of your mode)
  • write in it NODE_ENV=mymode
  • add in package.json a new run in "scripts" like vue-cli-service serve --mode mymode
  • Run it with the new command name (such as npm run mymode)
  • Use anywhere in your code both the injected env variables as well as the process.env variable such as:
if (process.env.NODE_ENV === 'mymode') {
  console.log("another mode!")
}

Tip mainly from here.