From 4ebe6f7ac8b3fac95e84920e4f61ca1b9463ba3b Mon Sep 17 00:00:00 2001 From: Alexandre Chopin Date: Mon, 12 Dec 2016 23:09:08 +0100 Subject: [PATCH] add html minifier for generate --- lib/generate.js | 6 +++++- package.json | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/generate.js b/lib/generate.js index 9632636ab2..133df7afe4 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -8,6 +8,7 @@ const pathToRegexp = require('path-to-regexp') const _ = require('lodash') const { resolve, join, dirname, sep } = require('path') const { promisifyRouteParams } = require('./utils') +const { minify } = require('html-minifier') const copy = pify(fs.copy) const remove = pify(fs.remove) const writeFile = pify(fs.writeFile) @@ -87,7 +88,10 @@ module.exports = function () { while (routes.length) { yield routes.splice(0, 500).map((route) => { return co(function * () { - const { html } = yield self.renderRoute(route) + var { html } = yield self.renderRoute(route) + html = minify(html, { + collapseWhitespace: true + }) var path = join(route, sep, 'index.html') // /about -> /about/index.html debug('Generate file: ' + path) path = join(distPath, path) diff --git a/package.json b/package.json index e853cbc229..85f494caf2 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "fs-extra": "^1.0.0", "glob": "^7.1.1", "hash-sum": "^1.0.2", + "html-minifier": "^3.2.3", "lodash": "^4.17.2", "lru-cache": "^4.0.2", "memory-fs": "^0.4.1",