Skip to content

Commit

Permalink
fix(hooks): 🔥 remove html-minifier
Browse files Browse the repository at this point in the history
fix #14
  • Loading branch information
kwaa committed Apr 30, 2022
1 parent 75a6ec8 commit 0742e65
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 141 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@sveltejs/adapter-static": "^1.0.0-next.29",
"@sveltejs/kit": "^1.0.0-next.320",
"@tailwindcss/typography": "^0.5.2",
"@types/html-minifier": "^4.0.2",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"chalk": "^4.1.2",
Expand All @@ -41,7 +40,6 @@
"eslint-plugin-svelte3": "^3.4.1",
"fenceparser": "^2.0.0",
"github-slugger": "^1.4.0",
"html-minifier": "^4.0.0",
"mdast-util-to-string": "^3.1.0",
"mdsvex": "^0.9.8",
"npm-run-all": "^4.1.5",
Expand Down
131 changes: 17 additions & 114 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 1 addition & 25 deletions src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
import type { Handle } from '@sveltejs/kit'
import { prerendering } from '$app/env'
import { minify } from 'html-minifier'
import { site } from '$lib/config/site'

const minificationOptions = {
collapseBooleanAttributes: true,
collapseWhitespace: true,
conservativeCollapse: true,
decodeEntities: true,
html5: true,
ignoreCustomComments: [/^#/],
minifyCSS: true,
minifyJS: true,
removeAttributeQuotes: true,
removeComments: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortAttributes: true,
sortClassName: true
}

export const handle: Handle = async ({ event, resolve }) =>
await resolve(event, {
transformPage: ({ html }) =>
prerendering
? minify(html.replace('<html lang="en">', `<html lang="${site.lang ?? 'en'}">`), minificationOptions)
: html.replace('<html lang="en">', `<html lang="${site.lang ?? 'en'}">`)
transformPage: ({ html }) => html.replace('<html lang="en">', `<html lang="${site.lang ?? 'en'}">`)
})

0 comments on commit 0742e65

Please sign in to comment.