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?
{ "name": "myapp", "scripts": { "gulp": "NODE_ENV='development' gulp", "gulp-build": "NODE_ENV='production' gulp" }, ... } Great answer.
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.
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.
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' ); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With