Guest User

build.js

a guest
Sep 12th, 2016
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var path = require('path');
  4. var gulp = require('gulp');
  5. var conf = require('./conf');
  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.     path.join(conf.paths.src, '/app/**/*.html'),
  14.     path.join(conf.paths.tmp, '/serve/app/**/*.html')
  15.   ])
  16.     .pipe($.htmlmin({
  17.       collapseWhitespace: true,
  18.       removeScriptTypeAttributes : true
  19.     }))
  20.     .pipe($.angularTemplatecache('templateCacheHtml.js', {
  21.       module: 'app',
  22.       root: 'app'
  23.     }))
  24.     .pipe(gulp.dest(conf.paths.tmp + '/partials/'));
  25. });
  26.  
  27. gulp.task('html', ['inject', 'partials'], function () {
  28.   var partialsInjectFile = gulp.src(path.join(conf.paths.tmp, '/partials/templateCacheHtml.js'), { read: false });
  29.   var partialsInjectOptions = {
  30.     starttag: '<!-- inject:partials -->',
  31.     ignorePath: path.join(conf.paths.tmp, '/partials'),
  32.     addRootSlash: false
  33.   };
  34.  
  35.   var htmlFilter = $.filter('*.html', { restore: true });
  36.   var jsFilter = $.filter('**/*.js', { restore: true });
  37.   var cssFilter = $.filter('**/*.css', { restore: true });
  38.   var assets;
  39.  
  40.   return gulp.src(path.join(conf.paths.tmp, '/serve/*.html'))
  41.     .pipe($.inject(partialsInjectFile, partialsInjectOptions))
  42.     .pipe(assets = $.useref.assets())
  43.     .pipe($.rev())
  44.     .pipe(jsFilter)
  45.     .pipe($.sourcemaps.init())
  46.     .pipe($.ngAnnotate())
  47.     .pipe($.uglify({ preserveComments: $.uglifySaveLicense })).on('error', conf.errorHandler('Uglify'))
  48.     .pipe($.sourcemaps.write('maps'))
  49.     .pipe(jsFilter.restore)
  50.     .pipe(cssFilter)
  51.     .pipe($.sourcemaps.init())
  52.     .pipe($.cleanCss({ processImport: false }))
  53.     .pipe($.sourcemaps.write('maps'))
  54.     .pipe(cssFilter.restore)
  55.     .pipe($.replace('../../bower_components/bootstrap/fonts/', '../fonts/'))
  56.     .pipe($.replace('../../bower_components/fontawesome/fonts/', '../fonts/'))
  57.     .pipe(assets.restore())
  58.     .pipe($.useref())
  59.     .pipe($.revReplace())
  60.     .pipe(htmlFilter)
  61.     .pipe($.htmlmin({
  62.       collapseWhitespace: true,
  63.       removeScriptTypeAttributes : true
  64.     }))
  65.     .pipe(htmlFilter.restore)
  66.     .pipe(gulp.dest(path.join(conf.paths.dist, '/')))
  67.     .pipe($.size({ title: path.join(conf.paths.dist, '/'), showFiles: true }));
  68.   });
  69.  
  70. // Only applies for fonts from bower dependencies
  71. // Custom fonts are handled by the "other" task
  72.  
  73.  
  74. gulp.task('fonts', function () {
  75.   return gulp.src($.mainBowerFiles())
  76.     .pipe($.filter('**/*.{otf,eot,svg,ttf,woff,woff2}'))
  77.     .pipe($.flatten())
  78.     .pipe(gulp.dest(path.join(conf.paths.dist, '/fonts/')));
  79. });
  80.  
  81. gulp.task('copyfonts', function() {
  82.     return gulp.src($.mainBowerFiles())
  83.     .pipe($.filter('**/*.{otf,eot,svg,ttf,woff,woff2}'))
  84.     .pipe($.flatten())
  85.     .pipe(gulp.dest(path.join(conf.paths.tmp, '/serve/fonts/')));
  86. });
  87.  
  88. gulp.task('other', function () {
  89.   var fileFilter = $.filter(function (file) {
  90.     return file.stat.isFile();
  91.   });
  92.  
  93.   return gulp.src([
  94.     path.join(conf.paths.src, '/**/*'),
  95.     path.join('!' + conf.paths.src, '/**/*.{html,css,js,less}')
  96.   ])
  97.     .pipe(fileFilter)
  98.     .pipe(gulp.dest(path.join(conf.paths.dist, '/')));
  99. });
  100.  
  101. gulp.task('clean', function () {
  102.   return $.del([path.join(conf.paths.dist, '/'), path.join(conf.paths.tmp, '/')]);
  103. });
  104.  
  105. gulp.task('build', ['html', 'fonts', 'copyfonts' 'other']);
Add Comment
Please, Sign In to add comment