|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var gulp = require('gulp'); |
| 4 | + |
| 5 | +// load plugins |
| 6 | +var $ = require('gulp-load-plugins')(); |
| 7 | + |
| 8 | +gulp.task('styles', function () { |
| 9 | + return gulp.src('app/styles/main.scss') |
| 10 | + .pipe($.rubySass({ style: 'expanded' })) |
| 11 | + .pipe($.autoprefixer('last 1 version')) |
| 12 | + .pipe(gulp.dest('.tmp/styles')) |
| 13 | + .pipe($.size()); |
| 14 | +}); |
| 15 | + |
| 16 | +gulp.task('scripts', function () { |
| 17 | + return gulp.src('app/scripts/**/*.js') |
| 18 | + .pipe($.jshint()) |
| 19 | + .pipe($.jshint.reporter($.jshintStylish)) |
| 20 | + .pipe($.size()); |
| 21 | +}); |
| 22 | + |
| 23 | +gulp.task('html', ['styles', 'scripts'], function () { |
| 24 | + var jsFilter = $.filter('**/*.js'); |
| 25 | + var cssFilter = $.filter('**/*.css'); |
| 26 | + |
| 27 | + return gulp.src('app/*.html') |
| 28 | + .pipe($.useref.assets()) |
| 29 | + .pipe($.rev()) |
| 30 | + .pipe(jsFilter) |
| 31 | + .pipe($.ngmin()) |
| 32 | + .pipe($.uglify()) |
| 33 | + .pipe(jsFilter.restore()) |
| 34 | + .pipe(cssFilter) |
| 35 | + .pipe($.csso()) |
| 36 | + .pipe(cssFilter.restore()) |
| 37 | + .pipe($.useref.restore()) |
| 38 | + .pipe($.useref()) |
| 39 | + .pipe($.revReplace()) |
| 40 | + .pipe(gulp.dest('dist')) |
| 41 | + .pipe($.size()); |
| 42 | +}); |
| 43 | + |
| 44 | +gulp.task('images', function () { |
| 45 | + return gulp.src('app/images/**/*') |
| 46 | + .pipe($.cache($.imagemin({ |
| 47 | + optimizationLevel: 3, |
| 48 | + progressive: true, |
| 49 | + interlaced: true |
| 50 | + }))) |
| 51 | + .pipe(gulp.dest('dist/images')) |
| 52 | + .pipe($.size()); |
| 53 | +}); |
| 54 | + |
| 55 | +gulp.task('fonts', function () { |
| 56 | + return $.bowerFiles() |
| 57 | + .pipe($.filter('**/*.{eot,svg,ttf,woff}')) |
| 58 | + .pipe($.flatten()) |
| 59 | + .pipe(gulp.dest('dist/fonts')) |
| 60 | + .pipe($.size()); |
| 61 | +}); |
| 62 | + |
| 63 | +gulp.task('clean', function () { |
| 64 | + return gulp.src(['.tmp', 'dist'], { read: false }).pipe($.clean()); |
| 65 | +}); |
| 66 | + |
| 67 | +gulp.task('build', ['html', 'images', 'fonts']); |
| 68 | + |
| 69 | +gulp.task('default', ['clean'], function () { |
| 70 | + gulp.start('build'); |
| 71 | +}); |
| 72 | + |
| 73 | +gulp.task('connect', function () { |
| 74 | + var connect = require('connect'); |
| 75 | + var app = connect() |
| 76 | + .use(require('connect-livereload')({ port: 35729 })) |
| 77 | + .use(connect.static('app')) |
| 78 | + .use(connect.static('.tmp')) |
| 79 | + .use(connect.directory('app')); |
| 80 | + |
| 81 | + require('http').createServer(app) |
| 82 | + .listen(9000) |
| 83 | + .on('listening', function () { |
| 84 | + console.log('Started connect web server on http://localhost:9000'); |
| 85 | + }); |
| 86 | +}); |
| 87 | + |
| 88 | +gulp.task('serve', ['connect', 'styles'], function () { |
| 89 | + require('opn')('http://localhost:9000'); |
| 90 | +}); |
| 91 | + |
| 92 | +// inject bower components |
| 93 | +gulp.task('wiredep', function () { |
| 94 | + var wiredep = require('wiredep').stream; |
| 95 | + |
| 96 | + gulp.src('app/styles/*.scss') |
| 97 | + .pipe(wiredep({ |
| 98 | + directory: 'app/bower_components' |
| 99 | + })) |
| 100 | + .pipe(gulp.dest('app/styles')); |
| 101 | + |
| 102 | + gulp.src('app/*.html') |
| 103 | + .pipe(wiredep({ |
| 104 | + directory: 'app/bower_components', |
| 105 | + exclude: ['bootstrap-sass-official'] |
| 106 | + })) |
| 107 | + .pipe(gulp.dest('app')); |
| 108 | +}); |
| 109 | + |
| 110 | +gulp.task('watch', ['connect', 'serve'], function () { |
| 111 | + var server = $.livereload(); |
| 112 | + |
| 113 | + // watch for changes |
| 114 | + |
| 115 | + gulp.watch([ |
| 116 | + 'app/*.html', |
| 117 | + '.tmp/styles/**/*.css', |
| 118 | + 'app/scripts/**/*.js', |
| 119 | + 'app/images/**/*' |
| 120 | + ]).on('change', function (file) { |
| 121 | + server.changed(file.path); |
| 122 | + }); |
| 123 | + |
| 124 | + gulp.watch('app/styles/**/*.scss', ['styles']); |
| 125 | + gulp.watch('app/scripts/**/*.js', ['scripts']); |
| 126 | + gulp.watch('app/images/**/*', ['images']); |
| 127 | + gulp.watch('bower.json', ['wiredep']); |
| 128 | +}); |
0 commit comments