Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set an environment variable as gulp task?

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?

like image 276
chacham15 Avatar asked Feb 28 '15 22:02

chacham15


People also ask

How do I set an environment variable in Gulp?

{ "name": "myapp", "scripts": { "gulp": "NODE_ENV='development' gulp", "gulp-build": "NODE_ENV='production' gulp" }, ... } Great answer.

How do you define a task in Gulp?

To have your tasks execute in order, use the series() method. For tasks to run at maximum concurrency, combine them with the parallel() method. Tasks are composed immediately when either series() or parallel() is called. This allows variation in the composition instead of conditional behavior inside individual tasks.

How will you set an environmental variable?

On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable.


1 Answers

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'     ); }); 
like image 132
Elise Chant Avatar answered Sep 21 '22 08:09

Elise Chant