diff options
author | Matt Strapp <matt@mattstrapp.net> | 2023-09-13 16:04:12 -0500 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2023-09-14 13:26:23 -0500 |
commit | 319a10b9a106e768ea2d3fb6d7134817911208ce (patch) | |
tree | d4d71c83665ff583071f387309980b6cdb893d88 /app/src/hooks.server.ts | |
parent | Initial commit (diff) | |
download | trinkets-319a10b9a106e768ea2d3fb6d7134817911208ce.tar trinkets-319a10b9a106e768ea2d3fb6d7134817911208ce.tar.gz trinkets-319a10b9a106e768ea2d3fb6d7134817911208ce.tar.bz2 trinkets-319a10b9a106e768ea2d3fb6d7134817911208ce.tar.lz trinkets-319a10b9a106e768ea2d3fb6d7134817911208ce.tar.xz trinkets-319a10b9a106e768ea2d3fb6d7134817911208ce.tar.zst trinkets-319a10b9a106e768ea2d3fb6d7134817911208ce.zip |
Add basic PWA support
TODO: draw the rest of the owl
Diffstat (limited to '')
-rw-r--r-- | app/src/hooks.server.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/app/src/hooks.server.ts b/app/src/hooks.server.ts new file mode 100644 index 0000000..163f640 --- /dev/null +++ b/app/src/hooks.server.ts @@ -0,0 +1,35 @@ +import { minify } from 'html-minifier-terser'; +import { building } from '$app/environment'; + +const minification_options = { + collapseBooleanAttributes: true, + collapseWhitespace: true, + conservativeCollapse: true, + decodeEntities: true, + html5: true, + ignoreCustomComments: [/^#/], + minifyCSS: true, + minifyJS: true, + removeAttributeQuotes: true, + removeComments: false, // some hydration code needs comments, so leave them in + removeOptionalTags: true, + removeRedundantAttributes: true, + removeScriptTypeAttributes: true, + removeStyleLinkTypeAttributes: true, + sortAttributes: true, + sortClassName: true +}; + +/** @type {import('@sveltejs/kit').Handle} */ +export async function handle({ event, resolve }) { + let page = ''; + + return resolve(event, { + transformPageChunk: ({ html, done }) => { + page += html; + if (done) { + return building ? minify(page, minification_options) : page; + } + } + }); +}
\ No newline at end of file |