Merge pull request #46 from akkolad/master

Add 3 tasks for sass in gulpfile.js
This commit is contained in:
Holger 2016-08-19 09:09:21 +02:00 committed by GitHub
commit 18027b7d7d
1 changed files with 45 additions and 0 deletions

View File

@ -30,10 +30,55 @@ var uglify = require('gulp-uglify');
var merge2 = require('merge2'); var merge2 = require('merge2');
var ignore = require('gulp-ignore'); var ignore = require('gulp-ignore');
var rimraf = require('gulp-rimraf'); var rimraf = require('gulp-rimraf');
var clone = require('gulp-clone');
var merge = require('gulp-merge');
var sourcemaps = require('gulp-sourcemaps'); var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync').create(); var browserSync = require('browser-sync').create();
var reload = browserSync.reload; var reload = browserSync.reload;
// Run:
// gulp sass + cssnano + rename
// Prepare the min.css for production (with 2 pipes to be sure that "child-theme.css" == "child-theme.min.css")
gulp.task('scss-for-prod', function() {
var source = gulp.src('./sass/*.scss')
.pipe(plumber())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sass());
var pipe1 = source.pipe(clone())
.pipe(sourcemaps.write(undefined, { sourceRoot: null }))
.pipe(gulp.dest('./css'));
var pipe2 = source.pipe(clone())
.pipe(cssnano())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./css'));
return merge(pipe1, pipe2);
});
// Run:
// gulp sourcemaps + sass + reload(browserSync)
// Prepare the child-theme.css for the developpment environment
gulp.task('scss-for-dev', function() {
gulp.src('./sass/*.scss')
.pipe(plumber())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sass())
.pipe(sourcemaps.write(undefined, { sourceRoot: null }))
.pipe(gulp.dest('./css'))
.pipe(reload({stream: true}));
});
gulp.task('watch-scss', ['browser-sync'], function () {
gulp.watch('./sass/**/*.scss', ['scss-for-dev']);
});
// Run: // Run:
// gulp sass // gulp sass
// Compiles SCSS files in CSS // Compiles SCSS files in CSS