Add gulp-htmlmin to minify HTML files (#137)

This commit is contained in:
Miguel Mayo 2018-11-14 08:30:03 -08:00 committed by Shawn Erquhart
parent d8cde69abc
commit acf8e37e9e
2 changed files with 13 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import postcssPresetEnv from "postcss-preset-env";
import BrowserSync from "browser-sync"; import BrowserSync from "browser-sync";
import webpack from "webpack"; import webpack from "webpack";
import webpackConfig from "./webpack.conf"; import webpackConfig from "./webpack.conf";
import minifyHtml from "gulp-htmlmin";
const browserSync = BrowserSync.create(); const browserSync = BrowserSync.create();
@ -73,6 +74,16 @@ function runServer(cb, hugoTask = "hugo") {
gulp.watch("./site/**/*", [hugoTask]); 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 * Run hugo and build the site
*/ */

View File

@ -6,7 +6,7 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"hugo": "gulp hugo", "hugo": "gulp hugo",
"build": "gulp build", "build": "gulp build && gulp minifyHtml",
"build-preview": "gulp build-preview", "build-preview": "gulp build-preview",
"start": "gulp server", "start": "gulp server",
"start-preview": "gulp server-preview", "start-preview": "gulp server-preview",
@ -33,6 +33,7 @@
"gulp-flatten": "^0.4.0", "gulp-flatten": "^0.4.0",
"gulp-postcss": "^8.0.0", "gulp-postcss": "^8.0.0",
"gulp-watch": "^5.0.1", "gulp-watch": "^5.0.1",
"gulp-htmlmin": "^5.0.1",
"hugo-bin": "^0.37.0", "hugo-bin": "^0.37.0",
"imports-loader": "^0.8.0", "imports-loader": "^0.8.0",
"plugin-error": "^1.0.1", "plugin-error": "^1.0.1",