perf: precompress HiCAD frontend assets
This commit is contained in:
parent
e4d527f0f2
commit
c8c6d9132a
@ -4,6 +4,7 @@
|
||||
location ^~ /vendor/zoo-modeling-app/assets/ {
|
||||
root /var/www/ai-chatbot/public;
|
||||
try_files $uri =404;
|
||||
gzip_static on;
|
||||
add_header Cache-Control "public, max-age=31536000, immutable" always;
|
||||
}
|
||||
|
||||
|
||||
@ -5,12 +5,14 @@ import {
|
||||
copyFileSync,
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
readdirSync,
|
||||
readFileSync,
|
||||
rmSync,
|
||||
writeFileSync,
|
||||
} from "node:fs";
|
||||
import { cp } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { gzipSync } from "node:zlib";
|
||||
|
||||
const repoUrl = "https://github.com/KittyCAD/modeling-app.git";
|
||||
const repoRef =
|
||||
@ -298,6 +300,17 @@ function ensureWasm() {
|
||||
copyFileSync(wasmBinary, path.join(sourceDir, "public/kcl_wasm_lib_bg.wasm"));
|
||||
}
|
||||
|
||||
function precompressVersionedAssets() {
|
||||
const assetsDir = path.join(outputDir, "assets");
|
||||
for (const entry of readdirSync(assetsDir, { withFileTypes: true })) {
|
||||
if (!entry.isFile() || !/\.(?:css|js)$/.test(entry.name)) {
|
||||
continue;
|
||||
}
|
||||
const assetPath = path.join(assetsDir, entry.name);
|
||||
writeFileSync(`${assetPath}.gz`, gzipSync(readFileSync(assetPath), { level: 9 }));
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
ensureOfficialSource();
|
||||
ensureDependencies();
|
||||
@ -329,6 +342,7 @@ async function main() {
|
||||
rmSync(outputDir, { force: true, recursive: true });
|
||||
mkdirSync(path.dirname(outputDir), { recursive: true });
|
||||
await cp(buildDir, outputDir, { recursive: true });
|
||||
precompressVersionedAssets();
|
||||
|
||||
const license = path.join(sourceDir, "LICENSE");
|
||||
if (existsSync(license)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user