0

For example, I have something like this:

  if(ENV === 'production') {
    grunt.registerTask('default', ['mkdir', 'copy', 'min']); // production
  } else {
    grunt.registerTask('default', ['mkdir', 'copy']); // dev
  }

if I do ENV=development grunt or grunt, I want dev task to be executed, and if I do ENV=production grunt, i want production task to be executed.

I cannot register two tasks: default-dev, default-prod and run grunt default-dev or grunt default-prod.

I have to use ENV variable to specify which task to run.

Sato
  • 8,192
  • 17
  • 60
  • 115
  • http://stackoverflow.com/a/33448470/1838811 you can use this to get `ENV` and use the code you posted – afuous Jul 11 '16 at 05:34

1 Answers1

2

Replace you ENV with process.env.NODE_ENV.

Refer Node.js docs

if (process.env.NODE_ENV === 'production') {
    grunt.registerTask('default', ['mkdir', 'copy', 'min']); // production
} else {
    grunt.registerTask('default', ['mkdir', 'copy']); // dev
}
Iceman
  • 6,035
  • 2
  • 23
  • 34