Last active
June 23, 2022 03:22
-
-
Save alxmtr/c852ff71cb35761d2215552c8bab40f1 to your computer and use it in GitHub Desktop.
Sass & Pug + BrowserSync
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
const { src, dest, watch, series } = require('gulp') | |
const pug = require('gulp-pug') | |
const sass = require('gulp-sass') | |
const browserSync = require('browser-sync').create() | |
// Compile pug files into HTML | |
function html() { | |
return src('src/pug/*.pug') | |
.pipe(pug()) | |
.pipe(dest('dist')) | |
} | |
// Compile sass files into CSS | |
function styles() { | |
return src('src/sass/main.sass') | |
.pipe(sass({ | |
includePaths: ['src/sass'], | |
errLogToConsole: true, | |
outputStyle: 'compressed', | |
onError: browserSync.notify | |
})) | |
.pipe(dest('dist/css')) | |
.pipe(browserSync.stream()) | |
} | |
// Copy assets | |
function assets() { | |
return src('src/assets/**/*') | |
.pipe(dest('dist/')) | |
} | |
// Serve and watch sass/pug files for changes | |
function watchAndServe() { | |
browserSync.init({ | |
server: 'dist', | |
}) | |
watch('src/sass/**/*.sass', styles) | |
watch('src/pug/*.pug', html) | |
watch('src/assets/**/*', assets) | |
watch('dist/*.html').on('change', browserSync.reload) | |
} | |
exports.html = html | |
exports.styles = styles | |
exports.watch = watchAndServe | |
exports.default = series(html, styles, assets, watchAndServe) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment