diff --git a/gulpfile.babel.js b/gulpfile.babel.js index c937555..f84132e 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -10,6 +10,7 @@ import postcssPresetEnv from "postcss-preset-env"; import BrowserSync from "browser-sync"; import webpack from "webpack"; import webpackConfig from "./webpack.conf"; +import minifyHtml from "gulp-htmlmin"; const browserSync = BrowserSync.create(); @@ -73,6 +74,16 @@ function runServer(cb, hugoTask = "hugo") { gulp.watch("./site/**/*", [hugoTask]); }; +// Html minify - gulp-htmlmin +gulp.task('minifyHtml', function() { + return gulp.src('./dist/**/*.html') + // Options below: https://github.com/kangax/html-minifier + .pipe(minifyHtml({collapseWhitespace: true})) + .pipe(minifyHtml({includeAutoGeneratedTags: false})) + .pipe(minifyHtml({removeComments: true})) + .pipe(gulp.dest('./dist')); +}); + /** * Run hugo and build the site */ diff --git a/package.json b/package.json index f250285..ab85a09 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "index.js", "scripts": { "hugo": "gulp hugo", - "build": "gulp build", + "build": "gulp build && gulp minifyHtml", "build-preview": "gulp build-preview", "start": "gulp server", "start-preview": "gulp server-preview", @@ -33,6 +33,7 @@ "gulp-flatten": "^0.4.0", "gulp-postcss": "^8.0.0", "gulp-watch": "^5.0.1", + "gulp-htmlmin": "^5.0.1", "hugo-bin": "^0.37.0", "imports-loader": "^0.8.0", "plugin-error": "^1.0.1",