mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-17 21:24:59 +00:00
minify HTML templates - fixes #15
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
"name": "sapper",
|
"name": "sapper",
|
||||||
"version": "0.9.3",
|
"version": "0.9.3",
|
||||||
"description": "Military-grade apps, engineered by Svelte",
|
"description": "Military-grade apps, engineered by Svelte",
|
||||||
"main": "middleware.js",
|
"main": "dist/middleware.ts.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"sapper": "./sapper"
|
"sapper": "./sapper"
|
||||||
},
|
},
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
"clorox": "^1.0.3",
|
"clorox": "^1.0.3",
|
||||||
"devalue": "^1.0.1",
|
"devalue": "^1.0.1",
|
||||||
"glob": "^7.1.2",
|
"glob": "^7.1.2",
|
||||||
|
"html-minifier": "^3.5.10",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"node-fetch": "^1.7.3",
|
"node-fetch": "^1.7.3",
|
||||||
"polka": "^0.3.4",
|
"polka": "^0.3.4",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import mkdirp from 'mkdirp';
|
|||||||
import rimraf from 'rimraf';
|
import rimraf from 'rimraf';
|
||||||
import devalue from 'devalue';
|
import devalue from 'devalue';
|
||||||
import { lookup } from './middleware/mime';
|
import { lookup } from './middleware/mime';
|
||||||
|
import { minify_html } from './middleware/minify_html';
|
||||||
import { create_routes, create_compilers } from './core';
|
import { create_routes, create_compilers } from './core';
|
||||||
import { dest, dev } from './config';
|
import { dest, dev } from './config';
|
||||||
import { Route, Template } from './interfaces';
|
import { Route, Template } from './interfaces';
|
||||||
@@ -113,7 +114,7 @@ const resolved = Promise.resolve();
|
|||||||
function get_route_handler(chunks: Record<string, string>, routes: RouteObject[]) {
|
function get_route_handler(chunks: Record<string, string>, routes: RouteObject[]) {
|
||||||
const template = dev()
|
const template = dev()
|
||||||
? () => fs.readFileSync('app/template.html', 'utf-8')
|
? () => fs.readFileSync('app/template.html', 'utf-8')
|
||||||
: (str => () => str)(fs.readFileSync('app/template.html', 'utf-8'));
|
: (str => () => str)(minify_html(fs.readFileSync('app/template.html', 'utf-8')));
|
||||||
|
|
||||||
function handle_route(route: RouteObject, req: Req, res: ServerResponse) {
|
function handle_route(route: RouteObject, req: Req, res: ServerResponse) {
|
||||||
req.params = route.params(route.pattern.exec(req.pathname));
|
req.params = route.params(route.pattern.exec(req.pathname));
|
||||||
|
|||||||
21
src/middleware/minify_html.ts
Normal file
21
src/middleware/minify_html.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { minify } from 'html-minifier';
|
||||||
|
|
||||||
|
export function minify_html(html: string) {
|
||||||
|
return minify(html, {
|
||||||
|
collapseBooleanAttributes: true,
|
||||||
|
collapseWhitespace: true,
|
||||||
|
conservativeCollapse: true,
|
||||||
|
decodeEntities: true,
|
||||||
|
html5: true,
|
||||||
|
minifyCSS: true,
|
||||||
|
minifyJS: true,
|
||||||
|
removeAttributeQuotes: true,
|
||||||
|
removeComments: true,
|
||||||
|
removeOptionalTags: true,
|
||||||
|
removeRedundantAttributes: true,
|
||||||
|
removeScriptTypeAttributes: true,
|
||||||
|
removeStyleLinkTypeAttributes: true,
|
||||||
|
sortAttributes: true,
|
||||||
|
sortClassName: true
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user