import { absolutePath } from "@ssot/paths"; import { compression } from "vite-plugin-compression2"; import { defineConfig } from "vite"; import { devCertificate } from "@project/scripts/web.scripts/build-dev-certificate.ts"; import { diagramPlugin } from "@project/scripts/web.scripts/build-diagrams.ts"; import { iconsPlugin } from "@project/scripts/web.scripts/build-icons.ts"; import { anatomyPlugin } from "@project/scripts/web.scripts/build-anatomy.ts"; import { chaptersPlugin } from "@project/scripts/web.scripts/build-chapters.ts"; import { join } from "node:path"; import { ontologyPlugin } from "@project/scripts/web.scripts/build-ontology.ts"; import { prerenderPlugin } from "@project/scripts/web.scripts/build-prerender.ts"; import { prunePlugin } from "@project/scripts/web.scripts/build-prune.ts"; const DEV_PORT = 4202; const COMPRESSION_THRESHOLD = 256; const CSP_NONCE_PLACEHOLDER = "__CSP_NONCE__"; export default defineConfig(async ({ mode }) => ({ base: "/", build: { assetsInlineLimit: 0, emptyOutDir: true, outDir: absolutePath("builds.web"), rollupOptions: { input: { main: join(absolutePath("app.member"), "index.html") }, output: { assetFileNames: "assets/[hash][extname]", chunkFileNames: "assets/[hash].js", entryFileNames: "assets/[hash].js", }, }, target: "esnext", }, html: { cspNonce: CSP_NONCE_PLACEHOLDER }, plugins: [ ontologyPlugin(), anatomyPlugin(), iconsPlugin(), diagramPlugin(), prerenderPlugin(), prunePlugin(), chaptersPlugin(), mode === "production" && compression({ algorithms: ["brotliCompress", "gzip"], threshold: COMPRESSION_THRESHOLD }), ], publicDir: absolutePath("app.public"), root: absolutePath("app.member"), server: { https: await devCertificate(), port: DEV_PORT, strictPort: true }, }));