Use @ndcode/html-minifier not html-minifier, request CSS and JS minification in HTML...
authorNick Downing <nick@ndcode.org>
Sun, 18 Nov 2018 13:03:21 +0000 (00:03 +1100)
committerNick Downing <nick@ndcode.org>
Sun, 18 Nov 2018 13:03:21 +0000 (00:03 +1100)
SiteRoot.js
package.json

index 82e42f0..cfcf40d 100644 (file)
@@ -7,7 +7,7 @@ let assert = require('assert')
 let disk_build = require('@ndcode/disk_build')
 //let emailjs = require('emailjs')
 let fs = require('fs')
-let html_minifier = require('html-minifier')
+let html_minifier = require('@ndcode/html-minifier')
 let jst = require('@ndcode/jst')
 let less = require('less/lib/less-node')
 let path = require('path')
@@ -197,7 +197,11 @@ SiteRoot.prototype.internal_get_html_min = function(pathname) {
           temp_pathname,
           html_minifier.minify(
             await fs_readFile(pathname, {encoding: 'utf-8'}),
-            {collapseWhitespace: true}
+            {
+              collapseWhitespace: true,
+              minifyCSS: true,
+              minifyJS: true
+            }
           ),
           {encoding: 'utf-8'}
         ),
@@ -593,6 +597,23 @@ SiteRoot.prototype.serve_css_min = async function(env, pathname) {
   return true
 }
 
+SiteRoot.prototype.serve_html_min = async function(env, pathname) {
+  if (pathname.slice(-9) !== '.html.min')
+    return false
+  let data 
+  try {
+    data = await this.internal_get_html_min(pathname)
+  }
+  catch (err) {
+    if (!(err instanceof Error) || err.code !== 'ENOENT')
+      throw err
+    return false
+  }
+  this.serve(env, 200, data, 'html_min')
+  return true
+}
+
 SiteRoot.prototype.serve_js_min = async function(env, pathname) {
   if (pathname.slice(-7) !== '.js.min')
     return false
@@ -610,6 +631,23 @@ SiteRoot.prototype.serve_js_min = async function(env, pathname) {
   return true
 }
 
+SiteRoot.prototype.serve_svg_min = async function(env, pathname) {
+  if (pathname.slice(-8) !== '.svg.min')
+    return false
+  let data 
+  try {
+    data = await this.internal_get_svg_min(pathname)
+  }
+  catch (err) {
+    if (!(err instanceof Error) || err.code !== 'ENOENT')
+      throw err
+    return false
+  }
+  this.serve(env, 200, data, 'svg_min')
+  return true
+}
+
 SiteRoot.prototype.serve_fs = async function(env, pathname) {
   let data 
   try {
@@ -648,8 +686,12 @@ SiteRoot.prototype.serve_file = async function(env, pathname) {
     return
   if (await this.serve_css_min(env, pathname + '.min'))
     return
+  if (await this.serve_html_min(env, pathname + '.min'))
+    return
   if (await this.serve_js_min(env, pathname + '.min'))
     return
+  if (await this.serve_svg_min(env, pathname + '.min'))
+    return
   if (await this.serve_fs(env, pathname))
     return
   this.die(env, `file not found ${env.pathname}`)
index 8509d77..4c6d486 100644 (file)
@@ -6,13 +6,13 @@
   "directories": {},
   "dependencies": {
     "@ndcode/build_cache": "^0.1.0",
-    "@ndcode/clean-css": "^0.1.0",
+    "@ndcode/clean-css": "^4.2.1",
     "@ndcode/disk_build": "^0.1.0",
+    "@ndcode/html-minifier": "^3.5.21",
     "@ndcode/json_cache": "^0.1.0",
     "@ndcode/jst": "^0.1.3",
     "commander": "^2.18.0",
     "fs": "^0.0.1-security",
-    "html-minifier": "^3.5.21",
     "http": "^0.0.0",
     "https": "^1.0.0",
     "less": "^3.8.1",