|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var gulp = require('gulp'); |
| 4 | + |
| 5 | +var paths = gulp.paths; |
| 6 | + |
| 7 | +var $ = require('gulp-load-plugins')({ |
| 8 | + pattern: ['gulp-*', 'main-bower-files', 'uglify-save-license', 'del'] |
| 9 | +}); |
| 10 | + |
| 11 | +gulp.task('partials', function () { |
| 12 | + return gulp.src([ |
| 13 | + paths.src + '/{app,components}/**/*.html', |
| 14 | + paths.tmp + '/{app,components}/**/*.html' |
| 15 | + ]) |
| 16 | + .pipe($.minifyHtml({ |
| 17 | + empty: true, |
| 18 | + spare: true, |
| 19 | + quotes: true |
| 20 | + })) |
| 21 | + .pipe($.angularTemplatecache('templateCacheHtml.js', { |
| 22 | + module: 'supportAdminApp' |
| 23 | + })) |
| 24 | + .pipe(gulp.dest(paths.tmp + '/partials/')); |
| 25 | +}); |
| 26 | + |
| 27 | +gulp.task('html', ['inject', 'partials'], function () { |
| 28 | + var partialsInjectFile = gulp.src(paths.tmp + '/partials/templateCacheHtml.js', { read: false }); |
| 29 | + var partialsInjectOptions = { |
| 30 | + starttag: '<!-- inject:partials -->', |
| 31 | + ignorePath: paths.tmp + '/partials', |
| 32 | + addRootSlash: false |
| 33 | + }; |
| 34 | + |
| 35 | + var htmlFilter = $.filter('*.html'); |
| 36 | + var jsFilter = $.filter('**/*.js'); |
| 37 | + var cssFilter = $.filter('**/*.css'); |
| 38 | + var assets; |
| 39 | + |
| 40 | + return gulp.src(paths.tmp + '/serve/*.html') |
| 41 | + .pipe($.inject(partialsInjectFile, partialsInjectOptions)) |
| 42 | + .pipe(assets = $.useref.assets()) |
| 43 | + .pipe($.rev()) |
| 44 | + .pipe(jsFilter) |
| 45 | + .pipe($.ngAnnotate()) |
| 46 | + .pipe($.uglify({preserveComments: $.uglifySaveLicense})) |
| 47 | + .pipe(jsFilter.restore()) |
| 48 | + .pipe(cssFilter) |
| 49 | + .pipe($.replace('../bootstrap/fonts', 'fonts')) |
| 50 | + .pipe($.csso()) |
| 51 | + .pipe(cssFilter.restore()) |
| 52 | + .pipe(assets.restore()) |
| 53 | + .pipe($.useref()) |
| 54 | + .pipe($.revReplace()) |
| 55 | + .pipe(htmlFilter) |
| 56 | + .pipe($.minifyHtml({ |
| 57 | + empty: true, |
| 58 | + spare: true, |
| 59 | + quotes: true |
| 60 | + })) |
| 61 | + .pipe(htmlFilter.restore()) |
| 62 | + .pipe(gulp.dest(paths.dist + '/')) |
| 63 | + .pipe($.size({ title: paths.dist + '/', showFiles: true })); |
| 64 | +}); |
| 65 | + |
| 66 | +gulp.task('images', function () { |
| 67 | + return gulp.src(paths.src + '/assets/images/**/*') |
| 68 | + .pipe(gulp.dest(paths.dist + '/assets/images/')); |
| 69 | +}); |
| 70 | + |
| 71 | +gulp.task('fonts', function () { |
| 72 | + return gulp.src($.mainBowerFiles()) |
| 73 | + .pipe($.filter('**/*.{eot,svg,ttf,woff}')) |
| 74 | + .pipe($.flatten()) |
| 75 | + .pipe(gulp.dest(paths.dist + '/fonts/')); |
| 76 | +}); |
| 77 | + |
| 78 | +gulp.task('fontawesome', function () { |
| 79 | + return gulp.src('bower_components/font-awesome/fonts/*.{eot,svg,ttf,woff}') |
| 80 | + .pipe(gulp.dest(paths.dist + '/fonts/')); |
| 81 | +}); |
| 82 | + |
| 83 | +gulp.task('misc', function () { |
| 84 | + return gulp.src(paths.src + '/**/*.ico') |
| 85 | + .pipe(gulp.dest(paths.dist + '/')); |
| 86 | +}); |
| 87 | + |
| 88 | +gulp.task('clean', function (done) { |
| 89 | + $.del([paths.dist + '/', paths.tmp + '/'], done); |
| 90 | +}); |
| 91 | + |
| 92 | +gulp.task('build', ['ng-config', 'html', 'images', 'fonts', 'fontawesome', 'misc']); |
0 commit comments