Skip to content

Instantly share code, notes, and snippets.

@jhades
Created May 21, 2016 21:27
Show Gist options
  • Save jhades/16e30eeaa3a397562b695930bfa58c55 to your computer and use it in GitHub Desktop.
Save jhades/16e30eeaa3a397562b695930bfa58c55 to your computer and use it in GitHub Desktop.
A complete toolchain for AngularJs - Gulp, Browserify, Sass
gulp.task('build-css', ['clean'], function() {
return gulp.src('./styles/*')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(cachebust.resources())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('./dist'));
});
gulp.task('build-js', ['clean'], function() {
var b = browserify({
entries: './js/app.js',
debug: true,
paths: ['./js/controllers', './js/services', './js/directives'],
transform: [ngAnnotate]
});
return b.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(cachebust.resources())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.on('error', gutil.log)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/js/'));
});
gulp.task('sprite', function () {
var spriteData = gulp.src('./images/*.png')
.pipe(spritesmith({
imgName: 'todo-sprite.png',
cssName: '_todo-sprite.scss',
algorithm: 'top-down',
padding: 5
}));
spriteData.css.pipe(gulp.dest('./dist'));
spriteData.img.pipe(gulp.dest('./dist'))
});
gulp.task('build', [ 'clean', 'bower','build-css','build-template-cache', 'jshint', 'build-js'], function() {
return gulp.src('index.html')
.pipe(cachebust.references())
.pipe(gulp.dest('dist'));
});
gulp.task('test', ['build-js'], function() {
var testFiles = [
'./test/unit/*.js'
];
return gulp.src(testFiles)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', function(err) {
console.log('karma tests failed: ' + err);
throw err;
});
});
gulp.task('jshint', function() {
gulp.src('/js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('webserver', ['watch','build'], function() {
gulp.src('.')
.pipe(webserver({
livereload: false,
directoryListing: true,
open: "<a href="http://localhost:8000/dist/index.html">http://localhost:8000/dist/index.html</a>"
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment