Skip to content

Instantly share code, notes, and snippets.

@zhuochun zhuochun/gulpfile-sass.js
Last active Jan 1, 2016

Embed
What would you like to do?
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var sass = require('gulp-sass');
var lr = require('tiny-lr'),
refresh = require('gulp-livereload'),
server = lr();
// Task SASS
gulp.task('sass', function() {
gulp.src([
'scss/**/*.scss',
'!scss/**/_*.scss'
])
.pipe(sass({
includePaths: ['scss']
}))
.pipe(gulp.dest('css'))
.pipe(refresh(server));
});
gulp.task('refresh', function() {
gulp.src([
'**/*.html',
'**/*.php'
])
.pipe(refresh(server));
});
// Task: default
gulp.task('default', function() {
gulp.run('sass');
server.listen(35729, function (error) {
if (error) return console.log(error);
gulp.watch([
'scss/**',
'img/**'
], function(event) {
gulp.run('sass');
});
gulp.watch([
'**/*.html',
'**.php'
], function(event) {
gulp.run('refresh');
});
});
});
var gulp = require('gulp'),
less = require('gulp-less'),
sass = require('gulp-sass'),
jshint = require('gulp-jshint'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename');
// lint
gulp.task('lint', function() {
gulp.src('./js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// compile sass
gulp.task('sass', function() {
gulp.src('./scss/*.scss')
.pipe(sass())
.pipe(gulp.dest('./css'));
});
// compile less
gulp.task('less', function() {
gulp.src('./less/*.less')
.pipe(less())
.pipe(gulp.dest('./css'));
});
// compile scripts
gulp.task('scripts', function() {
gulp.src('./js/*.js')
.pipe(concat('all.js'))
.pipe(gulp.dest('./dist'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./dist'));
});
// default task
gulp.task('default', function(){
gulp.run('lint', 'sass', 'scripts');
gulp.watch('./js/*.js', function(){
gulp.run('lint', 'sass', 'scripts');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.