Skip to content

Instantly share code, notes, and snippets.

@Tuizi
Created October 14, 2015 01:56
Show Gist options
  • Save Tuizi/66d5b593d4288ea8aefd to your computer and use it in GitHub Desktop.
Save Tuizi/66d5b593d4288ea8aefd to your computer and use it in GitHub Desktop.
Gulp + SCSS + Babel + Watch
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babel = require('babelify');
var sass = require('gulp-sass');
function compile(watch) {
var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel));
function rebundle() {
bundler.bundle()
.on('error', function(err) { console.error(err); this.emit('end'); })
.pipe(source('app.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./build'));
}
if (watch) {
bundler.on('update', function() {
console.log("-> babelifying...");
rebundle();
});
}
rebundle();
}
gulp.task('sass', function () {
gulp.src('style/src/style.scss')
.pipe(sass({outputStyle: 'compressed'}))
.pipe(gulp.dest('style/'));
});
gulp.task('watch', function () {
gulp.watch('./style/src/**/*.scss', ['sass']);
});
gulp.task('default', ['watch'], function () {
compile(true);
});
{
"devDependencies": {
"babelify": "^6.3.0",
"browserify": "^11.2.0",
"gulp": "^3.9.0",
"gulp-sass": "^2.0.4",
"gulp-sourcemaps": "^1.6.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment