From 8350dbfdbc54f0c1496eefc2288292c58bfea7ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= <seb@chopin.io>
Date: Sun, 21 May 2017 15:26:39 +0200
Subject: [PATCH] Disable minify with `generate.minify: false`

---
 lib/generate.js | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/lib/generate.js b/lib/generate.js
index a48241aa46..f8053455ac 100644
--- a/lib/generate.js
+++ b/lib/generate.js
@@ -45,7 +45,6 @@ export default async function () {
   ** Set variables
   */
   this.options.generate = _.defaultsDeep(this.options.generate, defaults)
-  var self = this
   var srcStaticPath = resolve(this.srcDir, 'static')
   var srcBuiltPath = resolve(this.dir, '.nuxt', 'dist')
   var distPath = resolve(this.dir, this.options.generate.dir)
@@ -53,7 +52,7 @@ export default async function () {
   /*
   ** Launch build process
   */
-  await self.build()
+  await this.build()
   /*
   ** Clean destination folder
   */
@@ -95,28 +94,32 @@ export default async function () {
   while (routes.length) {
     let n = 0
     await Promise.all(routes.splice(0, 500).map(async (route) => {
-      await waitFor(n++ * self.options.generate.interval)
+      await waitFor(n++ * this.options.generate.interval)
+      let html
       try {
-        var { html, error } = await self.renderRoute(route, { _generate: true })
-        if (error) {
-          errors.push({ type: 'handled', route, error })
+        const res = await this.renderRoute(route, { _generate: true })
+        html = res.html
+        if (res.error) {
+          errors.push({ type: 'handled', route, error: res.error })
         }
       } catch (err) {
         /* 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 (this.options.generate.minify) {
+        try {
+          html = minify(html, this.options.generate.minify)
+        } catch (err) /* istanbul ignore next */ {
+          const 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
+      let 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, html, 'utf8')
     }))
   }
   // Add .nojekyll file to let Github Pages add the _nuxt/ folder