Skip to content

Instantly share code, notes, and snippets.

@pxdsgnco
Created March 23, 2021 10:46
Show Gist options
  • Save pxdsgnco/0f0f24abfa553337516be12d6bf02bc8 to your computer and use it in GitHub Desktop.
Save pxdsgnco/0f0f24abfa553337516be12d6bf02bc8 to your computer and use it in GitHub Desktop.
Default gulpfile
var gulp = require("gulp"),
sass = require("gulp-sass"),
postcss = require("gulp-postcss"),
autoprefixer = require("autoprefixer"),
cssnano = require("cssnano"),
htmlmin = require("gulp-htmlmin"),
imagemin = require("gulp-imagemin"),
cache = require("gulp-cache"),
sourcemaps = require("gulp-sourcemaps");
var paths = {
styles: {
src: "src/assets/scss/**/*.scss",
dest: "src/assets/css",
},
};
// Define tasks after requiring dependencies
function style() {
return gulp
.src(paths.styles.src)
.pipe(soften(4))
.pipe(sourcemaps.init())
.pipe(sass())
.on("error", sass.logError)
.pipe(postcss([autoprefixer(), cssnano()]))
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.styles.dest));
}
// Set up image minification
function images() {
return gulp
.src("src/assets/images/**")
.pipe(
cache(
imagemin({
optimizationLevel: 9,
progressive: false,
interlaced: false,
})
)
)
.pipe(gulp.dest("src/assets/images"));
}
function watch() {
style();
browserSync.init({
server: {
baseDir: "./src",
},
});
gulp.watch(paths.styles.src, style);
gulp.watch("assets/images/**", images);
gulp.watch("./src/**/*.html", reload);
}
// Don't forget to expose the task!
exports.watch = watch;
exports.style = style;
exports.images = images;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment