Skip to content

Instantly share code, notes, and snippets.

Created November 20, 2014 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/85075675c3f86c4c1017 to your computer and use it in GitHub Desktop.
Save anonymous/85075675c3f86c4c1017 to your computer and use it in GitHub Desktop.
var gulp = require('gulp');
var path = require('path');
var fs = require('fs');
var paths = {
sass: {
watch: '../dev/sass/**/*.scss',
dest: '../web/assets/css/',
project: path.join(__dirname, '../dev')
},
js: {
watch: '../dev/js/*.js',
dest: path.join(__dirname, '../web/assets/js/')
}
};
gulp.task('watch', function() {
gulp.start('js');
var watch = require('gulp-watch');
watch(paths.sass.watch, ['sass']);
});
gulp.task('sass', function() {
var compass = require('gulp-compass');
gulp.src(paths.sass.watch)
.pipe(compass({
project: paths.sass.project,
css: paths.sass.dest,
sass: 'sass',
//style: 'compressed'
})).on('error', function(err) {
// Would like to catch the error here
});
});
gulp.task('js', function() {
var requires = {
'angular': './lib/angular-browserify.js',
'angular-ui-router': 'angular-ui-router',
'angular-translate': './lib/src/angular-translate/angular-translate.min.js',
'app': '../dev/js/app'
};
var entries = [{
dest: paths.js.dest,
debug: 'main.debug.js',
min: 'main.min.js',
entry: '../dev/js/main.js'
}];
entries.forEach(function (entry) {
createWatch(requires, entry);
});
});
function createWatch(requires, obj) {
var w = require('watchify')();
var streamify = require('gulp-streamify');
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
var dest = obj.dest,
min = obj.min,
debug = obj.debug,
entry = obj.entry;
Object.keys(requires).forEach(function(name) {
w.require(requires[name], {
expose: name
});
});
w.require(entry, {
entry: true
});
function build() {
w.bundle()
.pipe(source(min))
.pipe(streamify(uglify({
mangle: false
})))
.pipe(gulp.dest(dest));
w.bundle({
debug: true
})
.pipe(source(debug))
.pipe(gulp.dest(dest));
}
w.on('update', function() {
build();
});
w.on('log', function(msg) {
console.log(msg);
});
build();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment