diff --git a/gulpfile.js b/gulpfile.js index 9b2607c..a3d9599 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -8,10 +8,13 @@ const source = require('vinyl-source-stream'); const plumber = require('gulp-plumber'); const notifier = require('node-notifier'); const {build} = require('esbuild') +const imagemin = require('gulp-imagemin'); +const pngquant = require('imagemin-pngquant'); //Pathes var path = { + src: 'app/src', css: 'app/src/css', scss: 'app/src/scss', js: 'app/src/js', @@ -91,10 +94,11 @@ function serve(done) { } function watchFiles(done) { - watch(path.scss + '/*.scss', series(cleanDev, scss, buildCSS)); + watch(path.scss + '/**/*.scss', series(cleanDev, scss, buildCSS)); watch([path.js + '/**/*.js'], series(buildJS)); - - watch("app/*.html").on('change', reload); + watch([path.src + '/**/*.html'], series(copyHtml)); + + watch("app/**/*.html").on('change', reload); done(); } @@ -106,5 +110,32 @@ function notify(done) { done() } + + +function compressImg() { + return src(path.images + '/**/*') + .pipe(imagemin({ + progressive: true, + optimizationLevel: 7, + svgoPlugins: [{ + removeViewBox: false + }], + use: [pngquant()] + })) + .pipe(dest(path.production + '/img')); +} + +function copyFonts() { + return src(path.fonts + '/**/*') + .pipe(dest(path.production + "/fonts")); +} + +function copyHtml() { + return src(path.src + '/**/*.html') + .pipe(dest(path.production)); +} + exports.default = series(cleanDev, scss, buildCSS); exports.dev = series(cleanDev, scss, buildCSS, buildJS, watchFiles, notify, serve); + +exports.BuildProd = series(cleanFull, scss, buildCSS, buildJS, compressImg, copyFonts, copyHtml); diff --git a/package.json b/package.json index ea13048..b3d723a 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "index.html", "scripts": { "dev": "gulp dev", + "prod": "gulp BuildProd", "esbuild": "esbuild --bundle app/src/js/index.js" }, "repository": { @@ -27,10 +28,12 @@ "del": "^5.1.0", "esbuild": "^0.3.5", "gulp": "^4.0.2", + "gulp-imagemin": "^7.1.0", "gulp-notify": "^3.2.0", "gulp-plumber": "^1.2.1", "gulp-postcss": "^8.0.0", "gulp-sass": "^4.1.0", + "imagemin-pngquant": "^9.0.2", "node-notifier": "^7.0.0", "node-sass": "^4.14.1", "postcss-preset-env": "^6.7.0",