mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-16 21:04:34 +00:00
minify HTML at build time (also fixes #181)
This commit is contained in:
@@ -3,6 +3,7 @@ import * as path from 'path';
|
|||||||
import * as clorox from 'clorox';
|
import * as clorox from 'clorox';
|
||||||
import mkdirp from 'mkdirp';
|
import mkdirp from 'mkdirp';
|
||||||
import rimraf from 'rimraf';
|
import rimraf from 'rimraf';
|
||||||
|
import { minify_html } from './utils/minify_html';
|
||||||
import { create_compilers, create_main_manifests, create_routes, create_serviceworker_manifest } from '../core'
|
import { create_compilers, create_main_manifests, create_routes, create_serviceworker_manifest } from '../core'
|
||||||
import { locations } from '../config';
|
import { locations } from '../config';
|
||||||
|
|
||||||
@@ -40,6 +41,11 @@ export async function build() {
|
|||||||
console.log(clorox.inverse(`\nbuilt service worker`).toString());
|
console.log(clorox.inverse(`\nbuilt service worker`).toString());
|
||||||
console.log(serviceworker_stats.toString({ colors: true }));
|
console.log(serviceworker_stats.toString({ colors: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// minify app/template.html
|
||||||
|
// TODO compile this to a function? could be quicker than str.replace(...).replace(...).replace(...)
|
||||||
|
const template = fs.readFileSync(`${locations.app()}/template.html`, 'utf-8');
|
||||||
|
fs.writeFileSync(`${output}/template.html`, minify_html(template));
|
||||||
}
|
}
|
||||||
|
|
||||||
function compile(compiler: any) {
|
function compile(compiler: any) {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ 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 { locations, dev } from './config';
|
import { locations, dev } from './config';
|
||||||
import { Route, Template } from './interfaces';
|
import { Route, Template } from './interfaces';
|
||||||
@@ -113,8 +112,8 @@ 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(`${locations.app()}/template.html`, 'utf-8')
|
||||||
: (str => () => str)(minify_html(fs.readFileSync('app/template.html', 'utf-8')));
|
: (str => () => str)(fs.readFileSync(`${locations.dest()}/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));
|
||||||
|
|||||||
Reference in New Issue
Block a user