Skip to content

Instantly share code, notes, and snippets.

@rapsad
Forked from voter101/Gulpfile.js
Created January 23, 2016 21:10
Show Gist options
  • Save rapsad/cf7cf565462be64d6eb8 to your computer and use it in GitHub Desktop.
Save rapsad/cf7cf565462be64d6eb8 to your computer and use it in GitHub Desktop.
Gulpfile for Rails application with replaced Sprockets with Gulp
'use strict'
var gulp, sass, babelify, browserify, watchify, source, util;
gulp = require('gulp');
sass = require('gulp-sass');
babelify = require('babelify')
browserify = require('browserify');
watchify = require('watchify');
source = require('vinyl-source-stream');
util = require('gulp-util');
var sassPath, sassSource, jsSource;
sassPath = './app/assets/stylesheets/**/*.sass';
sassSource = ['./app/assets/stylesheets/application.sass'];
jsSource = './app/assets/javascripts/app.js';
function compile(watch) {
var bundler = watchify(browserify({entries: jsSource, debug: true}).transform(babelify));
function bundle() {
bundler.bundle()
.on('error', util.log.bind(util, "Browserify Error"))
.pipe(source('build.js'))
.pipe(gulp.dest('./public/assets'))
}
if (watch) {
bundler.on('update', function(){
console.log("Recompiling JS...");
bundle();
});
}
bundle();
}
gulp.task('default', ['compile-sass', 'compile-es6']);
gulp.task('compile-sass', function() {
gulp.src(sassSource)
.pipe(sass({ indentedSyntax: true, errLogToConsole: true }))
.pipe(gulp.dest('public/stylesheets'))
});
gulp.task('compile-es6', function() {
compile();
});
gulp.task('watch', ['watch-sass', 'watch-es6']);
gulp.task('watch-sass', function() {
gulp.watch(sassPath, ['compile-sass']);
});
gulp.task('watch-es6', function() {
compile(true)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment