chacham15 chacham15 - 2 months ago 18
Node.js Question

How can I set an environment variable from gulp?

I dont want to do

NODE_ENV='production' gulp
every time and would rather set the environment variable from within gulp via a task. How can I do this?

gulp.task('set-dev-node-env', function() {
    return process.env.NODE_ENV = 'development';

gulp.task('set-prod-node-env', function() {
    return process.env.NODE_ENV = 'production';

Use it like:

gulp.task('build_for_prod', ['set-prod-node-env'], function() {
    // maybe here manipulate config object  
    config.paths.src.scripts = config.paths.deploy.scripts;