Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. "use strict";
  2.  
  3. var gulp = require('gulp');
  4. var browserSync = require('browser-sync').create();
  5. var header = require('gulp-header');
  6. var cleanCSS = require('gulp-clean-css');
  7. var rename = require("gulp-rename");
  8. var uglify = require('gulp-uglify');
  9. var pkg = require('./package.json');
  10. var imageop = require('gulp-image-optimization');
  11. var uncss = require('gulp-uncss');
  12. // var browserify = require('gulp-browserify');
  13.  
  14. // Set the banner content
  15. var banner = ['/*!\n',
  16. ' * Start Bootstrap - <%= pkg.title %> v<%= pkg.version %> (<%= pkg.homepage %>)\n',
  17. ' * Copyright 2013-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n',
  18. ' */\n',
  19. ''
  20. ].join('');
  21.  
  22. // concatenate & minify CSS
  23. gulp.task('minify-css', function () {
  24. return gulp.src('src/css/*.css')
  25. .pipe(cleanCSS({compatibility: 'ie8'}))
  26. .pipe(rename({suffix: '.min'}))
  27. .pipe(gulp.dest('dist/css'))
  28. .pipe(browserSync.reload({
  29. stream: true
  30. }))
  31. });
  32.  
  33. // concatenate & minify JS
  34. gulp.task('minify-js', function () {
  35. return gulp.src('src/js/*js')
  36. .pipe(uglify())
  37. .pipe(header(banner, {pkg: pkg}))
  38. .pipe(rename({suffix: '.min'}))
  39. .pipe(gulp.dest('dist/js'))
  40. .pipe(browserSync.reload({
  41. stream: true
  42. }))
  43. });
  44.  
  45. gulp.task('image-optimization', function (cb) {
  46. gulp.src(['src/img/**/*.png', 'src/img/**/*.jpg', 'src/img/**/*.gif', 'src/img/**/*.jpeg']).pipe(imageop({
  47. optimizationLevel: 5,
  48. progressive: true,
  49. interlaced: true
  50. })).pipe(gulp.dest('dist/img')).on('end', cb).on('error', cb);
  51. });
  52.  
  53. // Run everything
  54. gulp.task('default', ['minify-css', 'minify-js', 'image-optimization']);
  55.  
  56. // Configure the browserSync task
  57. gulp.task('browserSync', function () {
  58. browserSync.init({
  59. server: {
  60. baseDir: ''
  61. },
  62. })
  63. })
  64.  
  65. // Dev task with browserSync
  66. gulp.task('dev', ['browserSync', 'minify-css', 'minify-js'], function () {
  67. gulp.watch('src/css/*.css', ['minify-css']);
  68. gulp.watch('src/js/*.js', ['minify-js']);
  69. // Reloads the browser whenever HTML or JS files change
  70. gulp.watch('pages/*.html', browserSync.reload);
  71. gulp.watch('dist/js/*.js', browserSync.reload);
  72. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement