A library for conditionally executing code in Gulp depending on an environment.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test Initial implementation Jul 13, 2015
.gitignore Initial implementation Jul 13, 2015
README.md Fix typo in README Aug 20, 2015
index.js Change the default environment to development Aug 20, 2015
package.json 0.1.2 Mar 9, 2017



A Gulp plug-in that makes it convenient to create separate environments, such as development and production, to run your tasks in.

Basic usage

Install the plugin using npm:

$ npm install --save-dev gulp-environments

Require the plug-in somewhere in your gulpfile.js

var environments = require('gulp-environments');

By default, the library defines two environments: development and production. For convenience sake, it is recommended to assign them to local variables:

var development = environments.development;
var production = environments.production;

You can use these environments as predicates (functions returning true/false depending on whether the given environment is active):

var source = production() ? "source.min.js" : "source.js";

You can also use the environment as a filter in you Gulp pipelines:

  // this will only init sourcemaps in development
  // only write out sourcemaps in development
  // only minify the compiled JS in production mode

Setting the environment

By default, gulp-environments uses the NODE_ENV environment variable to determine environment:

NODE_ENV=development gulp build

You can also pass a command line flag --env to set it:

gulp build --env development

Alternatively, you can define a task that would set the appropriate environment before executing other tasks:

gulp.task('set-dev', development.task);

and run it (or make it a dependency of a task that should also be run in that environment):

gulp set-dev build

Finally, you can always set the environment by hand in your task definition:


Other environments

You don't have to limit yourself to using only the two provided environments. You can create other ones by calling (in the example, we are creating an environment called staging):

var staging = environments.make("staging");




Adam Pohorecki