mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2026-01-15 12:15:02 +00:00
HTML Minify improvements
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"collapseBooleanAttributes": true,
|
||||
"collapseInlineTagWhitespace": true,
|
||||
"collapseWhitespace": true,
|
||||
"decodeEntities": true,
|
||||
"includeAutoGeneratedTags": false,
|
||||
"minifyJS": true,
|
||||
"minifyURLs": true,
|
||||
"removeAttributeQuotes": true,
|
||||
"removeComments": true,
|
||||
"removeEmptyAttributes": true,
|
||||
"removeOptionalTags": true,
|
||||
"removeRedundantAttributes": true,
|
||||
"removeScriptTypeAttributes": true,
|
||||
"removeStyleLinkTypeAttributes": true,
|
||||
"sortAttributes": true,
|
||||
"sortClassName": true,
|
||||
"trimCustomFragments": true,
|
||||
"useShortDoctype": true
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
"scripts": {
|
||||
"build": "npm run build:fs && npm run build:search && next build",
|
||||
"build:fs": "cd public && node ../scripts/fs2json.js --exclude .index --out .index/fs.9p.json . && node ../node_modules/browserfs/dist/scripts/make_http_index.js > .index/fs.bfs.json",
|
||||
"build:html": "html-minifier-terser --config-file .html-minifier.json --input-dir out --output-dir out --file-ext html",
|
||||
"build:html": "node scripts/minifyHtml.js",
|
||||
"build:robots": "node scripts/robots.js",
|
||||
"build:search": "node scripts/searchIndex.js",
|
||||
"deploy": "npm run build:robots && next export && npm run build:html",
|
||||
|
||||
49
scripts/minifyHtml.js
Normal file
49
scripts/minifyHtml.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const { readdirSync, readFileSync, writeFileSync } = require("fs");
|
||||
const { minify } = require("html-minifier-terser");
|
||||
const { extname, join } = require("path");
|
||||
|
||||
const OUT_PATH = "out";
|
||||
|
||||
const HTML_MINIFIER_CONFIG = {
|
||||
collapseBooleanAttributes: true,
|
||||
collapseInlineTagWhitespace: true,
|
||||
collapseWhitespace: true,
|
||||
decodeEntities: true,
|
||||
includeAutoGeneratedTags: false,
|
||||
minifyJS: true,
|
||||
minifyURLs: true,
|
||||
processConditionalComments: true,
|
||||
processScripts: ["text/html"],
|
||||
removeAttributeQuotes: true,
|
||||
removeComments: true,
|
||||
removeEmptyAttributes: true,
|
||||
removeOptionalTags: true,
|
||||
removeRedundantAttributes: true,
|
||||
removeScriptTypeAttributes: true,
|
||||
removeStyleLinkTypeAttributes: true,
|
||||
sortAttributes: true,
|
||||
sortClassName: true,
|
||||
trimCustomFragments: true,
|
||||
useShortDoctype: true,
|
||||
};
|
||||
|
||||
const CODE_REMOVE_FUNCTIONS = [
|
||||
(html) => html.replace(/<noscript (.*)><\/noscript>/, ""),
|
||||
(html) => html.replace(/<script (.*) nomodule=""><\/script>/, ""),
|
||||
(html) =>
|
||||
html.replace(/<style data-styled="" data-styled-version=(.*)>/, "<style>"),
|
||||
];
|
||||
|
||||
readdirSync(OUT_PATH).forEach(async (entry) => {
|
||||
if (extname(entry) === ".html") {
|
||||
const filPath = join(OUT_PATH, entry);
|
||||
const html = await readFileSync(filPath);
|
||||
let minifiedHtml = await minify(html.toString(), HTML_MINIFIER_CONFIG);
|
||||
|
||||
CODE_REMOVE_FUNCTIONS.forEach(
|
||||
(codeFunction) => (minifiedHtml = codeFunction(minifiedHtml))
|
||||
);
|
||||
|
||||
await writeFileSync(filPath, minifiedHtml);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user