Last active
January 29, 2019 12:35
-
-
Save wesleymonaro/b2f4e1755480d525b2ef297c6fc05625 to your computer and use it in GitHub Desktop.
Project base to minify SASS, CSS, JS and HTML files with Gulp.
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 autoprefixer = require("gulp-autoprefixer"); | |
const csso = require("gulp-csso"); | |
const del = require("del"); | |
const gulp = require("gulp"); | |
const htmlmin = require("gulp-htmlmin"); | |
const runSequence = require("run-sequence"); | |
const sass = require("gulp-sass"); | |
const uglify = require("gulp-uglify"); | |
const cleanCSS = require("gulp-clean-css"); | |
const rename = require("gulp-rename"); | |
const SUPOORTED_BROWSERS = [ | |
"ie >= 10", | |
"ie_mob >= 10", | |
"ff >= 30", | |
"chrome >= 34", | |
"safari >= 7", | |
"android >= 4.4", | |
"opera >= 23", | |
"ios >= 7" | |
]; | |
// Minify SASS files | |
gulp.task("sass", function() { | |
return gulp | |
.src("./src/sass/styles.scss") | |
.pipe( | |
sass({ | |
outputStyle: "nested", | |
precision: 10, | |
includePaths: ["."], | |
onError: console.error.bind(console, "Sass error:") | |
}) | |
) | |
.pipe(autoprefixer({ browsers: SUPOORTED_BROWSERS })) | |
.pipe(csso()) | |
.pipe( | |
rename({ | |
suffix: ".min" | |
}) | |
) | |
.pipe(gulp.dest("./dist/css")); | |
}); | |
// Minify CSS files | |
gulp.task("minify-css", () => { | |
return gulp | |
.src("./src/**/*/*.css") | |
.pipe(cleanCSS({ compatibility: "ie8" })) | |
.pipe( | |
rename({ | |
suffix: ".min" | |
}) | |
) | |
.pipe(gulp.dest("./dist")); | |
}); | |
// Minify JavaScript files | |
gulp.task("scripts", function() { | |
return gulp | |
.src("./src/js/**/*.js") | |
.pipe(uglify()) | |
.pipe( | |
rename({ | |
suffix: ".min" | |
}) | |
) | |
.pipe(gulp.dest("./dist/js")); | |
}); | |
// Minify HTML files | |
gulp.task("pages", function() { | |
return gulp | |
.src(["./src/**/*.html"]) | |
.pipe( | |
htmlmin({ | |
collapseWhitespace: true, | |
removeComments: true | |
}) | |
) | |
.pipe(gulp.dest("./dist")); | |
}); | |
// Clean dist directory | |
gulp.task("clean", () => del(["dist"])); | |
// Use sequence to execute all tasks | |
gulp.task("default", ["clean"], function() { | |
runSequence("minify-css", "sass", "scripts", "pages"); | |
}); |
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
{ | |
"name": "gulp-minifier", | |
"version": "0.1.0", | |
"description": "Project base to minify SASS, CSS, JS and HTML files with Gulp", | |
"license": "Apache-2.0", | |
"author": "Wesley Monaro", | |
"repository": { | |
"type": "git", | |
"url": "https://github.com/wesleymonaro/gulp-minifier" | |
}, | |
"devDependencies": { | |
"del": "^2.0.2", | |
"gulp": "^3.9.0", | |
"gulp-autoprefixer": "latest", | |
"gulp-clean-css": "^4.0.0", | |
"gulp-csso": "^2.0.0", | |
"gulp-htmlmin": "^3.0.0", | |
"gulp-rename": "^1.4.0", | |
"gulp-sass": "^2.0.0", | |
"gulp-uglify": "^2.0.0", | |
"run-sequence": "^1.2.2" | |
}, | |
"engines": { | |
"node": ">=0.12.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment