Using a single ternary in your default gulp task, you can have something like:
gulp.task('default',
[process.env.NODE_ENV === 'production' ? 'production' : 'development']
);
You will then be able to keep the single gulp
command in your package.json
and using this like you said:
NODE_ENV=production npm start
Any other value of your NODE_ENV
variable will launch the development
task.
You could of course do an advanced usage using an object allowing for multiple tasks and avoiding if
trees hell:
var tasks = {
development: 'development',
production: ['git', 'build', 'publish'],
preprod: ['build:preprod', 'publish:preprod'],
...
}
gulp.task('default', tasks[process.env.NODE_ENV] || 'fallback')
Keep in mind that when giving an array of tasks, they will be run in parallel.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…