How can I set an environment variable as gulp task?

chacham15 :

I don't want type the extra arguments NODE_ENV='production' gulp every time I run gulp to set an environment variable.

I would rather set the environment variable from within gulp via a task.

What would be a good way to achieve this?

Elise Chant :
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;
    runSequence(
        'build',
        's3'
    );
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to set environment variable for gulp-jasmine

How can I set runtime variable for docker compose environment variable

How can I get a task to set a variable that can be used in a configuration?

How can I check if an environment variable is set in Node.js?

How can I set the helm tiller namespace via an environment variable?

How can I set up the python environment variable on Windows 7?

How can I set .bash_profile environment variable in Dockerfile?

How can I set an environment variable which contains newline characters?

How can I set up an environment variable to work with TCC?

How can I consistently set an environment variable for a single program?

How can I set a runtime environment variable based on the value of another

How can I set the environment variable in request header for curl?

How can I set environment variable for another user account in Windows?

How can I pass a json variable set by set_fact to jq pipeline in ansible shell task?

How to set environment in ansible task only when variable is defined

How do I set an environment variable?

How can I trigger a gulp task with shell_exec()?

How can I restart my Gulp task on subsequent saves?

Gulp task - unable to set variable value

How can I set Task timeout in JavaFx?

How can I set the environment based on route?

How can I unset an environment variable in Kubernetes?

How can I check the environment variable in meteor

How can I require admin login on a Django site only if a certain environment variable is set?

How can I use jq to get the key value pairs only and set as environment variable?

Can I use an Expression to set a variable in a "SQL Statement Task"?

How can I properly kill a celery task in a kubernetes environment?

Can I set an environment variable on Bash's command line?

can i set node environment variable in Object format in Azure