add generate.minify can set boolean

false will skip html-minifier
true  will use default minify setting
This commit is contained in:
ausir 2017-05-21 21:03:11 +08:00
parent dd32b5441f
commit 4390b44814

View File

@ -41,6 +41,7 @@ const defaults = {
export default async function () {
const s = Date.now()
let errors = []
if (this.options.generate.minify === true) delete this.options.generate.minify
/*
** Set variables
*/
@ -105,18 +106,20 @@ export default async function () {
/* istanbul ignore next */
errors.push({ type: 'unhandled', route, error: err })
}
try {
var minifiedHtml = minify(html, self.options.generate.minify)
} catch (err) /* istanbul ignore next */ {
let minifyErr = new Error(`HTML minification failed. Make sure the route generates valid HTML. Failed HTML:\n ${html}`)
errors.push({ type: 'unhandled', route, error: minifyErr })
if (self.options.generate.minify !== false) {
try {
var minifiedHtml = minify(html, self.options.generate.minify)
} catch (err) /* istanbul ignore next */ {
let minifyErr = new Error(`HTML minification failed. Make sure the route generates valid HTML. Failed HTML:\n ${html}`)
errors.push({ type: 'unhandled', route, error: minifyErr })
}
}
var path = join(route, sep, 'index.html') // /about -> /about/index.html
debug('Generate file: ' + path)
path = join(distPath, path)
// Make sure the sub folders are created
await mkdirp(dirname(path))
await writeFile(path, minifiedHtml, 'utf8')
await writeFile(path, minifiedHtml || html, 'utf8')
}))
}
// Add .nojekyll file to let Github Pages add the _nuxt/ folder