Skip to content

Instantly share code, notes, and snippets.

@saruba
Created May 13, 2016 11:13
Show Gist options
  • Save saruba/0cafc1a88d1b8f7d023f1ef5cd370821 to your computer and use it in GitHub Desktop.
Save saruba/0cafc1a88d1b8f7d023f1ef5cd370821 to your computer and use it in GitHub Desktop.
gulpfile example
//Based on gulpfile.js from Google Web Starter Kit.
//and https://gist.github.com/soin08/4793992d8cc537f62df3
//https://github.com/google/web-starter-kit
'use strict';
// Include Gulp & Tools We'll Use
var gulp = require('gulp');
var autoPrefixer = require('gulp-autoprefixer');
var sourceMaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var changed = require('gulp-changed');
var size = require('gulp-size');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var gulpUtil = require('gulp-util');
var AUTOPREFIXER_BROWSERS = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
gulp.task('styles', function () {
gulp
.src(['./src/scss/**/*.scss'])
.pipe(sourceMaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourceMaps.write())
.pipe(autoPrefixer(AUTOPREFIXER_BROWSERS))
.pipe(concat('app.css'))
.pipe(gulp.dest('./dist/styles'));
});
// Copy web fonts to dist
gulp.task('fonts', function () {
return gulp.src(['./fonts/**'])
.pipe(gulp.dest('dist/fonts'))
.pipe(size({title: 'fonts'}));
});
gulp.task('vendorStyles', function () {
return gulp
.src([
'./bower_components/angular-material/angular-material.css'
])
.pipe(concat('vendor.css'))
.pipe(gulp.dest('./dist/styles'))
.pipe(size({title: 'vendorStyles'}));
});
gulp.task('vendor', ['vendorStyles'], function () {
return gulp
.src([
'./bower_components/jquery/dist/jquery.js',
'./bower_components/angular/angular.js',
'./bower_components/angular-animate/angular-animate.js',
'./bower_components/angular-aria/angular-aria.js',
'./bower_components/angular-cookies/angular-cookies.js',
'./bower_components/angular-material/angular-material.js',
'./bower_components/ngInfiniteScroll/build/ng-infinite-scroll.js',
'./bower_components/lodash/dist/lodash.js'
])
.pipe(concat('vendor.js'))
.pipe(gulp.dest('./dist/scripts'))
.pipe(size({title: 'vendor'}));
});
gulp.task('app', function () {
return gulp
.src(['./src/**/*.js'])
.pipe(changed('.tmp/scripts', {extension: '.js'}))
.pipe(concat('app.js'))
.pipe(gulp.dest('.tmp/scripts'))
.pipe(gulp.dest('./dist/scripts'))
.pipe(size({title: 'scripts'}));
});
// Watch Files For Changes
gulp.task('development',
['styles', 'vendor', 'app', 'fonts'],
function () {
gulp.watch('./src/scss/**/*.scss', ['styles']);
gulp.watch('./src/app/**/*.js', ['app']);
});
gulp.task('app.min', function () {
return gulp
.src([
'./src/**/*.js'
])
.pipe(changed('.tmp/scripts', {extension: '.js'}))
.pipe(concat('app.js'))
.pipe(gulp.dest('.tmp/scripts'))
.pipe(uglify())
//.on('error', gulpUtil.log)
//.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./dist/scripts'))
.pipe(size({title: 'scripts.min'}));
});
gulp.task('vendor.min', ['vendorStyles'], function () {
return gulp
.src([
'./bower_components/jquery/dist/jquery.min.js',
'./bower_components/angular/angular.min.js',
'./bower_components/angular-animate/angular-animate.min.js',
'./bower_components/angular-aria/angular-aria.min.js',
'./bower_components/angular-cookies/angular-cookies.min.js',
'./bower_components/angular-material/angular-material.min.js',
'./bower_components/ngInfiniteScroll/build/ng-infinite-scroll.min.js',
'./bower_components/lodash/dist/lodash.min.js'
])
.pipe(concat('vendor.min.js'))
.pipe(gulp.dest('./dist/scripts'))
.pipe(size({title: 'vendor.min'}));
});
gulp.task('production', ['fonts', 'styles', 'vendor.min', 'app.min']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment