Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // generated on 2017-02-10 using generator-gulp-webapp 1.1.1
  2. import gulp from 'gulp';
  3. import gulpLoadPlugins from 'gulp-load-plugins';
  4. import browserSync from 'browser-sync';
  5. import del from 'del';
  6. import {stream as wiredep} from 'wiredep';
  7.  
  8. const $ = gulpLoadPlugins();
  9. const reload = browserSync.reload;
  10.  
  11. gulp.task('styles', () => {
  12.   return gulp.src('app/styles/*.scss')
  13.     .pipe($.plumber())
  14.     .pipe($.sourcemaps.init())
  15.     .pipe($.sass.sync({
  16.       outputStyle: 'expanded',
  17.       precision: 10,
  18.       includePaths: ['.']
  19.     }).on('error', $.sass.logError))
  20.     .pipe($.autoprefixer({browsers: ['> 1%', 'last 2 versions', 'Firefox ESR']}))
  21.     .pipe($.sourcemaps.write())
  22.     .pipe(gulp.dest('.tmp/styles'))
  23.     .pipe(reload({stream: true}));
  24. });
  25.  
  26. gulp.task('scripts', () => {
  27.   return gulp.src('app/scripts/**/*.js')
  28.     .pipe($.plumber())
  29.     .pipe($.sourcemaps.init())
  30.     .pipe($.babel())
  31.     .pipe($.sourcemaps.write('.'))
  32.     .pipe(gulp.dest('.tmp/scripts'))
  33.     .pipe(reload({stream: true}));
  34. });
  35.  
  36. function lint(files, options) {
  37.   return () => {
  38.     return gulp.src(files)
  39.       .pipe(reload({stream: true, once: true}))
  40.       .pipe($.eslint(options))
  41.       .pipe($.eslint.format())
  42.       .pipe($.if(!browserSync.active, $.eslint.failAfterError()));
  43.   };
  44. }
  45. const testLintOptions = {
  46.   env: {
  47.     mocha: true
  48.   }
  49. };
  50.  
  51. gulp.task('lint', lint('app/scripts/**/*.js'));
  52. gulp.task('lint:test', lint('test/spec/**/*.js', testLintOptions));
  53.  
  54. gulp.task('html', ['styles', 'scripts'], () => {
  55.   return gulp.src('app/*.html')
  56.     .pipe($.useref({searchPath: ['.tmp', 'app', '.']}))
  57.     .pipe($.if('*.js', $.uglify()))
  58.     .pipe($.if('*.css', $.cssnano()))
  59.     .pipe($.if('*.html', $.htmlmin({collapseWhitespace: true})))
  60.     .pipe(gulp.dest('dist'));
  61. });
  62.  
  63. gulp.task('images', () => {
  64.   return gulp.src('app/images/**/*')
  65.     .pipe($.if($.if.isFile, $.cache($.imagemin({
  66.       progressive: true,
  67.       interlaced: true,
  68.       // don't remove IDs from SVGs, they are often used
  69.       // as hooks for embedding and styling
  70.       svgoPlugins: [{cleanupIDs: false}]
  71.     }))
  72.     .on('error', function (err) {
  73.       console.log(err);
  74.       this.end();
  75.     })))
  76.     .pipe(gulp.dest('dist/images'));
  77. });
  78.  
  79. gulp.task('fonts', () => {
  80.   return gulp.src(require('main-bower-files')('**/*.{eot,svg,ttf,woff,woff2}', function (err) {})
  81.     .concat('app/fonts/**/*'))
  82.     .pipe(gulp.dest('.tmp/fonts'))
  83.     .pipe(gulp.dest('dist/fonts'));
  84. });
  85.  
  86. gulp.task('extras', () => {
  87.   return gulp.src([
  88.     'app/*.*',
  89.     '!app/*.html'
  90.   ], {
  91.     dot: true
  92.   }).pipe(gulp.dest('dist'));
  93. });
  94.  
  95. gulp.task('clean', del.bind(null, ['.tmp', 'dist']));
  96.  
  97. gulp.task('serve', ['styles', 'scripts', 'fonts'], () => {
  98.   browserSync({
  99.     notify: false,
  100.     port: 9000,
  101.     server: {
  102.       baseDir: ['.tmp', 'app'],
  103.       routes: {
  104.         '/bower_components': 'bower_components'
  105.       }
  106.     }
  107.   });
  108.  
  109.   gulp.watch([
  110.     'app/*.html',
  111.     '.tmp/scripts/**/*.js',
  112.     'app/images/**/*',
  113.     '.tmp/fonts/**/*'
  114.   ]).on('change', reload);
  115.  
  116.   gulp.watch('app/styles/**/*.scss', ['styles']);
  117.   gulp.watch('app/scripts/**/*.js', ['scripts']);
  118.   gulp.watch('app/fonts/**/*', ['fonts']);
  119.   gulp.watch('bower.json', ['wiredep', 'fonts']);
  120. });
  121.  
  122. gulp.task('serve:dist', () => {
  123.   browserSync({
  124.     notify: false,
  125.     port: 9000,
  126.     server: {
  127.       baseDir: ['dist']
  128.     }
  129.   });
  130. });
  131.  
  132. gulp.task('serve:test', ['scripts'], () => {
  133.   browserSync({
  134.     notify: false,
  135.     port: 9000,
  136.     ui: false,
  137.     server: {
  138.       baseDir: 'test',
  139.       routes: {
  140.         '/scripts': '.tmp/scripts',
  141.         '/bower_components': 'bower_components'
  142.       }
  143.     }
  144.   });
  145.  
  146.   gulp.watch('app/scripts/**/*.js', ['scripts']);
  147.   gulp.watch('test/spec/**/*.js').on('change', reload);
  148.   gulp.watch('test/spec/**/*.js', ['lint:test']);
  149. });
  150.  
  151. // inject bower components
  152. gulp.task('wiredep', () => {
  153.   gulp.src('app/styles/*.scss')
  154.     .pipe(wiredep({
  155.       ignorePath: /^(\.\.\/)+/
  156.     }))
  157.     .pipe(gulp.dest('app/styles'));
  158.  
  159.   gulp.src('app/*.html')
  160.     .pipe(wiredep({
  161.       exclude: ['bootstrap-sass'],
  162.       ignorePath: /^(\.\.\/)*\.\./
  163.     }))
  164.     .pipe(gulp.dest('app'));
  165. });
  166.  
  167. gulp.task('build', ['html', 'images', 'fonts', 'extras'], () => {
  168.   return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true}));
  169. });
  170.  
  171. gulp.task('default', ['clean'], () => {
  172.   gulp.start('build');
  173. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement