Created
March 12, 2015 17:38
-
-
Save benfoster/955933d0efc77ca78924 to your computer and use it in GitHub Desktop.
Gulp File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'), | |
$ = require('gulp-load-plugins')({ | |
pattern: [ | |
'gulp-*', | |
'gulp.*', | |
'del', | |
'run-sequence', | |
'main-bower-files' | |
] | |
}); | |
// Path settings for Gulp | |
var appRoot = './', | |
config = { | |
less: { | |
file: appRoot + 'assets/less/app.less', | |
src: appRoot + 'assets/less/**/*.less' | |
}, | |
html: { | |
src: appRoot + appRoot + 'app/**/*.html', | |
templateCache: { | |
file: 'templates.js', | |
options: { | |
module: 'fabrik.core', | |
root: 'app/', | |
standAlone: false | |
} | |
} | |
}, | |
bower: { | |
src: appRoot + 'bower_components', | |
filter: [ | |
'**/*/jquery.js', // ensure jQuery included first | |
'**/*.js', | |
'!**/*.min.js' // don't include min files | |
], | |
dest: 'libs.min.js' | |
}, | |
scripts: { | |
src: [ | |
// it's important that we load modules first, then everything else | |
// TODO these should be appRoot prefixed | |
'app/**/*.module.js', | |
'app/**/*.js', | |
'!app/boot.js', | |
'!app/form-helpers.js', | |
'assets/dist/templates.js' // include the compiled templates | |
], | |
dest: 'app.min.js' | |
}, | |
output: appRoot + 'assets/dist' | |
}; | |
// Gulp task for cleaning the output directory | |
gulp.task('build-clean', function (cb) { | |
$.del([config.output], cb); | |
}); | |
// Gulp task for compiling Less and minifying | |
gulp.task('build-styles', function () { | |
return gulp.src(config.less.file) | |
.pipe($.sourcemaps.init()) | |
// compile less | |
.pipe($.less()) | |
.pipe(gulp.dest(config.output)) | |
.pipe($.rename({ suffix: '.min' })) | |
.pipe($.minifyCss({ | |
keepSpecialComments: 0 | |
})) | |
.pipe($.sourcemaps.write('./')) // write source maps to a separate file | |
.pipe(gulp.dest(config.output)) | |
.pipe($.notify({ | |
onLast: true, | |
message: 'Build Styles Complete.' | |
})); | |
}); | |
// Gulp Task for bundling and minifying bower dependencies | |
gulp.task('build-libs', function () { | |
return gulp.src($.mainBowerFiles(config.bower.filter)) | |
.pipe($.sourcemaps.init()) | |
.pipe($.concat(config.bower.dest)) | |
.pipe($.uglify()) | |
.pipe($.sourcemaps.write('./')) // write source map to a separate file | |
.pipe(gulp.dest(config.output)) | |
.pipe($.notify({ | |
onLast: true, | |
message: 'Build Libs Complete' | |
})); | |
}); | |
// Gulp task for creating Angular Template Cache | |
gulp.task('build-templates', function () { | |
return gulp.src(config.html.src) | |
.pipe($.minifyHtml({ empty: true })) | |
.pipe($.angularTemplatecache( | |
config.html.templateCache.file, | |
config.html.templateCache.options | |
)) | |
.pipe(gulp.dest(config.output)) | |
.pipe($.notify({ | |
onLast: true, | |
message: 'Build Templates Complete' | |
})); | |
}); | |
// Gulp task for bundling and minifying app scripts | |
gulp.task('build-scripts', function () { | |
return gulp.src(config.scripts.src) | |
.pipe($.sourcemaps.init()) | |
.pipe($.concat(config.scripts.dest)) | |
.pipe($.uglify()) | |
.pipe($.sourcemaps.write('./')) // write source map as a separate file | |
.pipe(gulp.dest(config.output)) | |
.pipe($.notify({ | |
onLast: true, | |
message: 'Build Scripts Complete' | |
})); | |
}); | |
// Gulp Task for VS Build | |
// This will run in this order: | |
// * build-clean | |
// * build-libs, build-styles, build-templates in parallel | |
// * build-scripts | |
gulp.task('build', function (callback) { | |
$.runSequence('build-clean', | |
['build-libs', 'build-styles', 'build-templates'], | |
'build-scripts', | |
callback); | |
}); | |
// Gulp Watch Task | |
// Watches for changes to app, bower packages and | |
gulp.task('watch', ['build'], function () { | |
gulp.watch(config.less.src, ['build-styles']); | |
gulp.watch(config.html.src, ['build-templates', 'build-scripts']); | |
gulp.watch(config.scripts.src, ['build-scripts']); | |
gulp.watch(config.bower.src, ['build-libs']); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment