Skip to content

Instantly share code, notes, and snippets.

@rliberoff
Last active June 26, 2024 14:57
Show Gist options
  • Save rliberoff/4053bdca34ba623ed4f8c5c78409cd7d to your computer and use it in GitHub Desktop.
Save rliberoff/4053bdca34ba623ed4f8c5c78409cd7d to your computer and use it in GitHub Desktop.
Gulp file for transpiling SASS (`.scss`) to CSS.
/*
This requires node and the following dev dependencies.
`npm install gulp gulp-sass gulp-purgecss sass --save-dev`
Then execute `gulp`
Remember that any file that starts with underscore ('_') is kind of ignored by convention, and no `.css` file is generated.
For example `_variables.scss`.
*/
const { src, dest, watch, series } = require('gulp')
const sass = require('gulp-sass')(require('sass'))
const purgecss = require('gulp-purgecss')
function buildStyles() {
return src('*.scss')
.pipe(sass())
.pipe(purgecss({ content: ['*.html'] })) // This cleans up any unused class or style from SCSS.
.pipe(dest('css'))
}
function watchTask() {
watch(['*.scss'], buildStyles)
}
exports.default = series(buildStyles, watchTask)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment