Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  const gulp = require('gulp'),
  2.        sass = require('gulp-sass'),
  3.        server = require('browser-sync').create(),
  4.        pug = require('gulp-pug'),
  5.        pugLinter = require('gulp-pug-linter'),
  6.        htmlValidator = require('gulp-w3c-html-validator'),
  7.        autoprefixer = require('gulp-autoprefixer'),
  8.        shorthand = require('gulp-shorthand'),
  9.        cleanCSS = require('gulp-clean-css'),
  10.        sourcemaps = require('gulp-sourcemaps'),
  11.        imagemin = require('gulp-imagemin'),
  12.        plumber = require('gulp-plumber')
  13.  
  14. function pug2html() {
  15.   return gulp.src('src/pages/*.pug')
  16.     .pipe(sourcemaps.init())
  17.     .pipe(plumber())
  18.     .pipe(pugLinter({ reporter: 'default' }))
  19.     .pipe(pug())
  20.     .pipe(htmlValidator())
  21.     .pipe(gulp.dest('build'))
  22. }
  23.  
  24. function style() {
  25.   return gulp.src('./src/scss/**/*.scss')
  26.     .pipe(sass().on('error', sass.logError))
  27.     .pipe(autoprefixer({
  28.       cascade: false
  29.     }))
  30.     .pipe(shorthand())
  31.     .pipe(cleanCSS({
  32.       compatibility: 'ie8'
  33.     }))
  34.     // .pipe(gulp.dest('./build/css'))
  35. }
  36.  
  37. function minifyImg() {
  38.   return gulp.src('./src/img/**/*')
  39.     .pipe(imagemin())
  40.     .pipe(gulp.dest('build/img'))
  41. }
  42.  
  43. function serve(cb) {
  44.   server.init({
  45.     server: 'build',
  46.     notify: false,
  47.     open: true,
  48.     cors: true
  49.   })
  50.  
  51.   gulp.watch('src/img/**/*.{gif,png,jpg,jpeg,svg,webp}', gulp.series(minifyImg)).on('change', server.reload)
  52.   gulp.watch('src/scss/**/*.scss', gulp.series(style, cb =>
  53.     gulp.src('build/css').pipe(server.stream()).on('end', cb)))
  54.   gulp.watch('src/pages/**/*.pug', gulp.series(pug2html))
  55.   gulp.watch('build/*.html').on('change', server.reload)
  56.  
  57.   return cb()
  58. }
  59.  
  60. module.exports.start = gulp.series(style, minifyImg,pug2html, serve)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement