Last active
August 29, 2015 14:08
-
-
Save Kenty/1a0c36e0d93764fcad3d to your computer and use it in GitHub Desktop.
My gulp setting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// Gulp | |
var gulp = require( 'gulp' ); | |
// Plugins | |
var $ = require('gulp-load-plugins')(); | |
var del = require('del'); | |
var runSequence = require('run-sequence'); | |
var browserSync = require('browser-sync'); | |
var reload = browserSync.reload; | |
var pkg = require('./package.json'); | |
var info = '// <%= pkg.name %>@v<%= pkg.version %>, <%= pkg.license %>\n'; | |
// Autoprefixer | |
var AUTOPREFIXER_BROWSERS = [ | |
'ie >= 10', | |
'ie_mob >= 10', | |
'ff >= 30', | |
'chrome >= 34', | |
'safari >= 7', | |
'opera >= 23', | |
'ios >= 7', | |
'android >= 4.4', | |
'bb >= 10' | |
]; | |
// Paths | |
var paths = { | |
'scssSrc': '_scss/**/*.scss', | |
'bowerZFSrc': 'bower-components/foundation/', | |
'jsSrc': 'js/**/*.js', | |
'rootDir': './' | |
}; | |
// Display error function, to format and make custom errors | |
var displayError = function( error ) { | |
// initial building up of the error | |
var errorString = '[' + error.plugin + ']'; | |
errorString += ' ' + error.message.replace( '\n', '' ); | |
// If the error contains the filename or line number add it to the string | |
if ( error.fileName ) { | |
errorString += ' in ' +error.fileName; | |
} | |
if ( error.lineNumber ) { | |
errorString += ' on line ' + error.lineNumber; | |
} | |
// This woll output am error like the following: | |
// [gulp-sass ] error message in file_name on line 1 | |
console.error( errorString ); | |
}; | |
// gulp.task( 'default', function() { | |
// console.log( "Hello World!!" ); | |
// }); | |
// Compile sass for gulp-sass | |
// gulp.task( 'sass', function() { | |
// return gulp.src(paths.scssSrc) | |
// .pipe($.sourcemaps.init()) | |
// .pipe($.plumber()) | |
// // .pipe($.sass(options.sass)) | |
// .pipe($.sass({ | |
// // sourceMap: 'scss', | |
// // sourceComments: 'map', | |
// includePaths: [paths.scssSrc, paths.bowerZFSrc + 'scss'], | |
// // outputStyle: 'expanded', | |
// })) | |
// .on( 'error', function( err ) { | |
// displayError( err ); | |
// }) | |
// .pipe($.autoprefixer( | |
// 'last 2 version', 'safari 5', 'ie 9', 'opera 12.1', 'ios 6', 'android 4' | |
// )) | |
// .pipe($.sourcemaps.write()) | |
// .pipe(gulp.dest(paths.rootDir/* + 'assets/css/dest'*/)) | |
// .pipe($.if('*.css', $.csso())) | |
// // .pipe($.rename({ | |
// // suffix: '.min' | |
// // })) | |
// .pipe(gulp.dest(paths.rootDir + 'assets/dest/css')) | |
// .pipe($.size({title: 'sass'})) | |
// .pipe(reload({ | |
// stream: true, | |
// once: true, | |
// })); | |
// }); | |
// Compile and Automatically Prefix Stylesheets | |
gulp.task('sass', function () { | |
// For best performance, don't add Sass partials to `gulp.src` | |
return gulp.src([ | |
paths.scssSrc, | |
]) | |
.pipe($.plumber()) | |
// .pipe($.sourcemaps.init()) | |
.pipe($.rubySass({ | |
bundleExec: true, | |
style: 'expanded', | |
// 'sourcemap=none': true, | |
sourcemapPath: './', | |
loadPath: paths.bowerZFSrc + 'scss', | |
precision: 10 | |
})) | |
.on( 'error', function( err ) { | |
displayError( err ); | |
}) | |
// .pipe($.sourcemaps.write()) | |
.pipe(gulp.dest(paths.rootDir)) | |
.pipe($.sourcemaps.init({loadMaps: true})) | |
.pipe($.autoprefixer({ | |
browsers: AUTOPREFIXER_BROWSERS | |
})) | |
.pipe($.if('*.css', $.csso())) | |
// // .pipe($.rename({ | |
// // suffix: '.min' | |
// // })) | |
.pipe($.sourcemaps.write('./', {addComment: true})) | |
.pipe(gulp.dest(paths.rootDir + 'assets/dest/css')) | |
.pipe($.size({title: 'sass'})) | |
.pipe(reload({ | |
stream: true, | |
once: true, | |
})); | |
}); | |
// Script | |
gulp.task('script', function() { | |
return gulp.src([paths.jsSrc]) | |
.pipe($.plumber()) | |
.pipe($.jshint('.jshintrc')) | |
.pipe($.jshint.reporter('jshint-stylish')) | |
.pipe($.if(!browserSync.active, $.jshint.reporter('fail'))) | |
.on( 'error', function( err ) { | |
displayError( err ); | |
}) | |
// .pipe($.sourcemaps.init()) | |
.pipe($.uglify({preserveComments: 'some'})) | |
// .pipe($.concat('all.js')) | |
// .pipe($.sourcemaps.write()) | |
.pipe(gulp.dest('assets/dest/js')) | |
.pipe($.size()) | |
.pipe(reload({stream: true, once: true})); | |
}); | |
// Clean Output Directory | |
gulp.task('clean', del.bind(null, ['assets/dest'])); | |
gulp.task('build', ['clean'], function (cb) { | |
runSequence('sass', ['script'], cb); | |
}); | |
gulp.task( 'default', /*['watch'],*/ function() { | |
gulp.watch( paths.scssSrc, ['sass'], reload ) | |
.on('change', function(evt) { | |
console.log( | |
'[watcher] File ' + evt.path.replace(/.*(?=sass)/,'') + ' was ' + evt.type + ', compiling...' | |
); | |
}); | |
gulp.watch( paths.jsSrc, ['script'], reload ); | |
}); | |
// browserSync | |
gulp.task( 'serve', function() { | |
browserSync.init(null, { | |
// server: { | |
// baseDir: paths.rootDir, | |
// // proxy: 'wordpress.local' | |
// }, | |
proxy: 'wordpress.local', | |
xip: true | |
}); | |
gulp.watch( paths.scssSrc, ['sass'], reload ) | |
.on('change', function(evt) { | |
console.log( | |
'[watcher] File ' + evt.path.replace(/.*(?=sass)/,'') + ' was ' + evt.type + ', compiling...' | |
); | |
}); | |
gulp.watch( './**/*.php', reload ); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "dm-gulp-task", | |
"version": "0.1.0", | |
"description": "Base framework foundation with gulp", | |
"main": "gulpfile.js", | |
"devDependencies": { | |
"browser-sync": "*", | |
"csso": "^1.3.11", | |
"del": "*", | |
"gulp": "*", | |
"gulp-autoprefixer": "*", | |
"gulp-changed": "*", | |
"gulp-concat": "*", | |
"gulp-csso": "^0.2.9", | |
"gulp-if": "*", | |
"gulp-imagemin": "*", | |
"gulp-jshint": "*", | |
"gulp-load-plugins": "*", | |
"gulp-minify-css": "*", | |
"gulp-newer": "*", | |
"gulp-plumber": "*", | |
"gulp-prettify": "*", | |
"gulp-rename": "*", | |
"gulp-ruby-sass": "^0.7.1", | |
"gulp-sass": "*", | |
"gulp-size": "^1.0.0", | |
"gulp-sourcemaps": "*", | |
"gulp-uglify": "*", | |
"jshint-stylish": "*", | |
"run-sequence": "*" | |
}, | |
"scripts": { | |
"start": "gulp", | |
"gulpsever": "gulp serve", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Kenta Hoshino", | |
"license": "MIT" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment