Skip to content

Instantly share code, notes, and snippets.

@chyngyz
Last active February 22, 2016 04:31
Show Gist options
  • Save chyngyz/07b6a228e20413a94ff9 to your computer and use it in GitHub Desktop.
Save chyngyz/07b6a228e20413a94ff9 to your computer and use it in GitHub Desktop.
Gulpfile.js
'use strict';
var gulp = require('gulp');
var notify = require("gulp-notify");
var Path = {
rootDir: 'dev',
rootDist: 'dist',
staticJs: 'dev/js',
staticCSS: 'dev/styles',
staticMedia: 'dev/media',
staticImg: 'dev/images',
staticFonts: 'dev/fonts'
};
// Load plugins
var $ = require('gulp-load-plugins')();
// Styles
gulp.task('styles', function () {
return gulp.src(Path.staticCSS + '/**/*.scss')
.pipe($.sass().on('error', $.sass.logError))
.pipe($.csso())
.pipe(gulp.dest(Path.rootDist + '/styles'))
.pipe($.size());
});
// Scripts
gulp.task('scripts', function () {
return gulp.src(Path.staticJs + '/**/*.js')
.pipe($.jshint('.jshintrc'))
.pipe($.jshint.reporter('default'))
.pipe($.concat('all.js'))
.pipe(gulp.dest(Path.rootDist + '/js'))
.pipe($.size());
});
// Images
gulp.task('images', function () {
return gulp.src(Path.staticImg + '/**/*')
.pipe($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(Path.rootDist + '/img'))
.pipe($.size());
});
// Media
gulp.task('media', function(){
return gulp.src(Path.staticMedia + '**/*')
.pipe(gulp.dest(Path.rootDist + '/img'));
});
// Fonts
gulp.task('fonts', function() {
return gulp.src(Path.staticFonts +'/**/*')
.pipe(gulp.dest(Path.rootDist + '/fonts'));
});
// Clean
gulp.task('clean', function () {
return gulp.src(Path.rootDist, { read: false }).pipe($.rimraf());
});
// Build
gulp.task('build', ['styles','scripts', 'images', 'media', 'fonts']);
// Default task
gulp.task('default', ['clean'], function () {
gulp.start('build');
});
// Watch
gulp.task('serve', ['default'], function () {
// Watch .css files
gulp.watch(Path.staticCSS + '/*.scss', ['styles']);
// Watch .js files
gulp.watch(Path.staticJs + '/**/*.js', ['scripts']);
// Watch image files
gulp.watch(Path.staticImg + '/**/*', ['images']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment