Skip to content

Instantly share code, notes, and snippets.

@davebeach
Last active September 10, 2016 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davebeach/a40acc62ea4e073924952fc941de06c3 to your computer and use it in GitHub Desktop.
Save davebeach/a40acc62ea4e073924952fc941de06c3 to your computer and use it in GitHub Desktop.

GULP Workflow

Steps to set up project.

  1. Create project folder. mkdir projectName
  2. Initialize npm project. npm init
  3. Setup project gulpfile.js:
{
  "name": "projectName",
  "version": "1.0.0",
  "description": "projectDescription",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "gulp",
    "sass"
  ],
  "author": "David Beach",
  "license": "MIT"
}
  1. Install components, starting with gulp. npm install --save-dev gulp

  2. Base SASS items npm install --save-dev gulp-sass gulp-cssnano gulp-sourcemaps gulp-autoprefixer

  3. Verify package.json

"devDependencies": {
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.0",
"gulp-cssnano": "^2.1.1",
"gulp-sass": "^2.2.0",
"gulp-sourcemaps": "^1.6.0"
}
  1. Next time, you just have to add to the package.json file the stuff you need, then run npm install

  2. Also to update packages, input the new version in package.json file, and run npm install

  3. Set up gulpfile.js

'use strict';

var gulp = require('gulp');
var sass = require('gulp-sass');
var cssnano = require('gulp-cssnano');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');

gulp.task('workflow', function () {
	gulp.src('./src/sass/**/*.scss')
		.pipe(sourcemaps.init())
		.pipe(sass().on('error', sass.logError))
		.pipe(autoprefixer({
			browsers: ['last 2 versions'],
			cascade: false
		}))
		.pipe(cssnano())
		.pipe(sourcemaps.write('./'))

	.pipe(gulp.dest('./dist/css/'))
});

gulp.task('default', function () {
	gulp.watch('./src/sass/**/*.scss', ['workflow']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment