import { readFileSync } from "node:fs"; import { join } from "node:path"; import { defineConfig } from "vite"; export default defineConfig({ base: "/account/", build: { target: "es2023", modulePreload: { polyfill: false }, }, plugins: [{ name: "runtime-licenses", generateBundle() { const packages = new Map(); for (const id of this.getModuleIds()) { const root = id.match(/(.*\/node_modules\/(?:@[^/]+\/)?[^/]+)/)?.[1]; if (root) { const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8")) as { name: string; version: string }; packages.set(`${pkg.name}@${pkg.version}`, root); } } const notices = [...packages].sort(([left], [right]) => left.localeCompare(right)) .map(([name, root]) => `${name}\n\n${readFileSync(join(root, "LICENSE"), "utf8")}`); this.emitFile({ type: "asset", fileName: "licenses.txt", source: notices.join("\n\n") }); }, }], });