Created
May 22, 2014 11:17
-
-
Save Deraen/9488df411b61fbe6c831 to your computer and use it in GitHub Desktop.
Gulp & Usemin
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
| /* jshint node: true */ | |
| var gulp = require('gulp'); | |
| var plumber = require('gulp-plumber'); | |
| var path = 'app/'; | |
| // Common | |
| var less = require('gulp-less'); | |
| function compileLess() { | |
| return gulp.src(path + 'styles/main.less') | |
| .pipe(plumber()) | |
| .pipe(less({ | |
| paths: [path + 'styles'], | |
| })) | |
| .pipe(gulp.dest('./tmp/styles')); | |
| } | |
| // Dev | |
| var livereload = require('gulp-livereload'); | |
| var gprint = require('gulp-print'); | |
| var watch = require('gulp-watch'); | |
| gulp.task('less', function() { | |
| return compileLess(); | |
| }); | |
| gulp.task('default', ['less'], function() { | |
| gulp.watch(path + 'styles/*.less', ['less']); | |
| watch({glob: '{' + path + ',.tmp}/**/*.{css,js,html}', emitOnGlob: false}, function(files) { | |
| return files | |
| .pipe(gprint()) | |
| .pipe(livereload()); | |
| }); | |
| }); | |
| // Build dist | |
| var clean = require('gulp-clean'); | |
| var usemin = require('gulp-usemin'); | |
| var uglify = require('gulp-uglify'); | |
| var ngmin = require('gulp-ngmin'); | |
| var minifyHtml = require('gulp-minify-html'); | |
| var rev = require('gulp-rev'); | |
| var sourcemaps = require('gulp-sourcemaps'); | |
| gulp.task('clean', function() { | |
| return gulp.src('build/', {read: false}).pipe(clean()); | |
| }); | |
| gulp.task('less:dist', ['clean'], function() { | |
| return compileLess(); | |
| }); | |
| gulp.task('copy:dist', ['clean'], function() { | |
| return gulp.src('app/components/font-awesome/fonts/*', {base: 'app/'}) | |
| .pipe(gulp.dest('build/')); | |
| }); | |
| gulp.task('build', ['clean', 'less:dist', 'copy:dist'], function() { | |
| return gulp.src(path + '{views/**/*,*}.html') | |
| .pipe(usemin({ | |
| css: [rev()], | |
| html: [minifyHtml({empty: true})], | |
| vendorjs: [sourcemaps.init(), uglify(), rev(), sourcemaps.write('.')], | |
| js: [sourcemaps.init(), ngmin(), uglify(), rev(), sourcemaps.write('.')], | |
| })) | |
| .pipe(gulp.dest('build/')); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment