Last active
May 19, 2019 22:18
-
-
Save gostrafx/292871805733009e7cf90abfba758894 to your computer and use it in GitHub Desktop.
gulpfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const {src, dest, watch, series, parallel, lastRun} = require('gulp'); | |
const del = require('del'); | |
const autoprefixer = require('autoprefixer'); | |
const cssnano = require('cssnano'); | |
const concat = require('gulp-concat'); | |
const browserSync = require('browser-sync'); | |
const uglify = require('gulp-uglify'); | |
const postcss = require('gulp-postcss'); | |
const sass = require('gulp-sass'); | |
const waitDelay = require('gulp-wait2'); | |
sass.compiler = require('node-sass'); | |
// File path variables | |
const files = { | |
scssPath: 'src/scss/**/*.scss', | |
jsPath: 'src/js/**/*.js', | |
imgPath: 'src/img/**/*.{jpg,png,svg,gif}', | |
htmlPath: 'src/**/*.html' | |
}; | |
const folder = { | |
default: 'dist/', | |
imgPath: 'dist/assets/img/', | |
cssPath: 'dist/assets/css/', | |
jsPath: 'dist/assets/js/' | |
}; | |
// Html task | |
function htmlTask() { | |
return src(files.htmlPath) | |
.pipe(dest(folder.default)) | |
.pipe(browserSync.stream()); | |
} | |
// Scss task | |
function scssTask() { | |
return src(files.scssPath, {sourcemaps: true}) | |
.pipe(waitDelay(500)) | |
.pipe(sass()) | |
.pipe(postcss([autoprefixer()])) | |
.pipe(dest(folder.cssPath, {sourcemaps: '.'})) | |
.pipe(browserSync.stream()); | |
} | |
/* | |
// Js task | |
function jsTask() { | |
return src(files.jsPath) | |
.pipe(concat('vendor.js')) | |
.pipe(uglify()) | |
.pipe(dest(folder.jsPath)) | |
.pipe(browserSync.stream()); | |
} | |
// Img task | |
function imgTask() { | |
return src('src/img/!**!/!*.+(jpg|jpeg|gif|png)', {since: lastRun(imgTask)}) | |
.pipe(dest(folder.imgPath)); | |
} | |
*/ | |
// Watch task | |
function watchTask() { | |
browserSync.init({ | |
server: { | |
baseDir: folder.default | |
} | |
}); | |
//watch([files.htmlPath, files.scssPath, files.jsPath], series(htmlTask, scssTask, jsTask)); | |
//watch('src/img/**/*.+(jpg|jpeg|gif|png)', {ignoreInitial: false}, imgTask); | |
watch([files.htmlPath, files.scssPath], series(htmlTask, scssTask)); | |
watch(files.htmlPath).on('change', browserSync.reload); | |
} | |
// Clean dist task | |
function clear() { | |
return del(folder.default); | |
} | |
// Default task | |
module.exports = { | |
//default: series(htmlTask, scssTask, jsTask, imgTask, watchTask), | |
default: series(htmlTask, scssTask, watchTask), | |
clear | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment