Setting up environments for development and production
Of course, you will need your build process to develop your project, but after that you will run different tasks to get your code ready for production. In the development stage, you need CSS code with CSS sourcemaps for easy debugging, and in the production stage, you probably will minify the CSS code without CSS sourcemaps.
The gulp-environments
plugin makes it convenient to create separate environments, such as development and production, to run your tasks in. You can install this plugin by running the following command:
npm install --save-dev gulp-environments
Then add the plugin to your Gulpfile.js
file, which should look like this:
var environments = require('gulp-environments');
Then assign the environments as follows:
var development = environments.development; var production = environments.production;
Now you can pass a command line flag --env
to set the environment:
gulp build --env development
You can also, conditionally assign...