Guest User

Untitled

a guest
Jul 17th, 2019
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const gulp = require('gulp');
  2.  
  3. const sass = require('gulp-sass');
  4. const browserSync = require('browser-sync').create();
  5. const useref =require('gulp-useref');
  6. // to filter the content
  7. const gulpIf = require('gulp-if');
  8. // to remove files
  9. const del = require('del');
  10. const postcss = require('gulp-postcss');
  11. const sourcemaps = require('gulp-sourcemaps');
  12. const autoprefixer = require('autoprefixer');
  13. var babel = require("gulp-babel");
  14. let imagemin = require('gulp-imagemin');
  15. let pngquant = require('imagemin-pngquant');
  16.  
  17.  
  18.  
  19.  
  20. gulp.task('browserSync', function(done) {
  21. browserSync.init({
  22. server: {baseDir: './'},
  23. });
  24. done();
  25. });
  26.  
  27. // Compile sass into CSS & auto-inject into browsers
  28. gulp.task('sass', function() {
  29. return (gulp.src('css/*.scss')
  30. .pipe(sourcemaps.init())
  31. .pipe(sass()).on('error', sass.logError)
  32. .pipe(sourcemaps.write('.'))
  33. .pipe(gulp.dest('css/'))
  34. .pipe(browserSync.stream())
  35. )
  36. });
  37.  
  38. gulp.task('default', gulp.series('browserSync', function watching () {
  39. gulp.watch('css/*.scss').on('change', gulp.series('sass'));
  40. gulp.watch('css/*.css').on('change', browserSync.reload);
  41. gulp.watch('index.html').on('change', browserSync.reload);
  42. //gulp.watch('index.html', browserSync.reload);// reloads only once
  43. gulp.watch('js/*.js').on('change', browserSync.reload);
  44. gulp.watch('img/').on('change', browserSync.reload);
  45. }))
  46.  
  47. gulp.task('combi', function() {
  48. return gulp.src('index.html')
  49. .pipe(useref())
  50. .pipe(gulpIf('*.js', babel()))
  51. .pipe(gulpIf('*.css', postcss([ autoprefixer() ])))
  52. .pipe(gulp.dest('dist/'))
  53. });
  54. gulp.task('img', function () {
  55. return gulp.src('img/*')
  56. .pipe(imagemin([
  57. imagemin.svgo(),
  58. pngquant({
  59. quality: [0.7, 0.9],
  60. speed: 1,
  61. dithering: 0.5
  62. })
  63. ]))
  64.  
  65. .pipe(gulp.dest('dist/img'));
  66.  
  67. });
  68.  
  69. gulp.task('clean:dist', function(){
  70. return del(['dist']).then(paths => {
  71. console.log('Deleted files and folders:\n', paths.join('\n'));
  72. });
  73. });
  74.  
  75. gulp.task('fonts', function() {
  76. return gulp.src('fonts/*').pipe(gulp.dest('dist/fonts'));
  77. })
  78.  
  79. gulp.task('build', gulp.series('clean:dist', 'sass', gulp.parallel('combi', 'img', 'fonts'))
  80. );
RAW Paste Data