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')
temp_pathname,
html_minifier.minify(
await fs_readFile(pathname, {encoding: 'utf-8'}),
- {collapseWhitespace: true}
+ {
+ collapseWhitespace: true,
+ minifyCSS: true,
+ minifyJS: true
+ }
),
{encoding: 'utf-8'}
),
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
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 {
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}`)
"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",