Last active
July 22, 2022 17:51
-
-
Save vanessa-dev/bdbf962c32493c855539b7c735a2efb6 to your computer and use it in GitHub Desktop.
Minificando arquivo css e js com 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 gulp = require('gulp'); | |
const uglify = require('gulp-uglify'); | |
const concat = require('gulp-concat'); | |
const cleanCSS = require('gulp-clean-css'); | |
const rename = require('gulp-rename'); | |
// Dev Paths | |
const js_src = "./assets_dev/js/**/*.js"; | |
const css_src = "./assets_dev/css/**/*.css"; | |
// Dist Paths | |
const js_dest = "./assets/js"; | |
const js_file_name = "scripts.min.js"; | |
const css_dest = "./assets/css"; | |
const css_file_name = "style.min.css"; | |
// Scripts Task | |
gulp.task('minify-js', function() { | |
return gulp.src(js_src) | |
.pipe(uglify()) | |
.pipe(concat(js_file_name )) | |
.pipe(gulp.dest(js_dest)); | |
}); | |
gulp.task('minify-css', function() { | |
return gulp.src(css_src) | |
.pipe(cleanCSS()) | |
.pipe(rename(css_file_name)) | |
.pipe(gulp.dest(css_dest)); | |
}); | |
gulp.task('watch', function(){ | |
gulp.watch(css_src, gulp.series('minify-css')); | |
gulp.watch(js_src, gulp.series('minify-js')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dependencias do package.json:
"dependencies": {
"gulp": "^4.0.2",
"gulp-clean-css": "^4.3.0",
"gulp-concat": "^2.6.1",
"gulp-minify-css": "^1.2.4",
"gulp-plumber": "^1.2.1",
"gulp-rename": "^2.0.0",
"gulp-uglify": "^3.0.2"
}