Skip to content

Instantly share code, notes, and snippets.

@iPotaje
Created November 24, 2015 18:40
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 iPotaje/ef6d086fa17b0736b6a2 to your computer and use it in GitHub Desktop.
Save iPotaje/ef6d086fa17b0736b6a2 to your computer and use it in GitHub Desktop.
gulpfile.js For angular, angular-route, browserify, watchify and babelify
var gulp = require('gulp');
var dest = {
preDirectory : 'pre',
directory : 'dist',
bundle : '/' + 'all.js'
};
var src = {
webserver : '.',
angularModules : 'js/*.js',
angularTemplates : 'partials/*.html',
alljs : [
dest.preDirectory + '/*.js'
]
};
var webserver = require('gulp-webserver');
gulp.task('webserver', function() {
gulp.src(src.webserver)
.pipe(webserver({
livereload: true,
directoryListing: true,
open: true
}));
});
var ngAnnotate = require('gulp-ng-annotate');
gulp.task('annotate', ['clean'], function () {
return gulp.src(src.angularModules)
.pipe(ngAnnotate())
.pipe(gulp.dest(dest.preDirectory));
});
var templateCache = require('gulp-angular-templatecache');
gulp.task('templates', ['clean'], function () {
return gulp.src(src.angularTemplates)
.pipe(templateCache({standalone: true}))
.pipe(gulp.dest(dest.preDirectory));
});
var concat = require('gulp-concat');
var plumber = require('gulp-plumber');
gulp.task('scripts',['annotate', 'templates'], function(ok) {
// plumber(del(['pre/all.js'], ok));
return gulp.src(src.alljs)
.pipe(plumber())
.pipe(concat(dest.bundle))
.pipe(gulp.dest(dest.preDirectory));
});
var uglify = require('gulp-uglify');
var del = require('del');
gulp.task('compress', ['scripts'], function() {
// del('pre/all.js');
return gulp.src(dest.preDirectory + dest.bundle)
.pipe(uglify())
.pipe(gulp.dest(dest.directory));
});
gulp.task('cleanf', function (){
del(dest.preDirectory);
del(['pre/all.js', 'app/app.min.js']);
});
gulp.task('clean', function () {
return del.sync(['pre'])
});
gulp.task("watcher", function (){
gulp.watch(src.angularModules, ['clean', 'annotate', 'templates', 'scripts', 'browserify']);
gulp.watch(src.angularTemplates, ['clean', 'annotate' , 'templates', 'scripts', 'browserify'])
});
var browserify = require('browserify')
var watchify = require('watchify')
var babelify = require('babelify')
var source = require('vinyl-source-stream')
var buffer = require('vinyl-buffer')
var rename = require('gulp-rename')
function bundle_js(bundler) {
return bundler.bundle()
.pipe(source('all.js'))
.pipe(buffer())
.pipe(rename('app.min.js'))
// .pipe(uglify())
.pipe(gulp.dest('app'))
}
gulp.task('watchify',['scripts'], function () {
var bundler = watchify(browserify('pre/all.js', { debug: true }))
.transform(babelify, {
presets: ['es2015']
})
bundle_js(bundler)
bundler.on('update', function () {
console.log("event");
bundle_js(bundler)
})
})
// Without watchify
gulp.task('browserify',['scripts'], function () {
var bundler = browserify('pre/all.js', { debug: true })
.transform(babelify, {
presets: ['es2015']
})
return bundle_js(bundler)
})
gulp.task('default', ['annotate', 'templates', 'scripts', 'watcher','webserver']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment