From 8aa62cec7da98a380d18c35f771e44f2fe681f7c Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Sun, 8 Sep 2024 02:26:42 +0800 Subject: [PATCH] build: adapt new vite version --- vite.config.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/vite.config.ts b/vite.config.ts index 7e9aaa5..a31a248 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,9 +1,20 @@ import { crx } from "@crxjs/vite-plugin"; import react from "@vitejs/plugin-react"; -import { defineConfig } from "vite"; +import { defineConfig, Plugin } from "vite"; import { viteStaticCopy } from "vite-plugin-static-copy"; import pkg from "./package.json"; +// https://github.com/crxjs/chrome-extension-tools/issues/846#issuecomment-1861880919 +const viteManifestHackIssue846: Plugin & { renderCrxManifest: (manifest: any, bundle: any) => void } = { + // Workaround from https://github.com/crxjs/chrome-extension-tools/issues/846#issuecomment-1861880919. + name: "manifestHackIssue846", + renderCrxManifest(_manifest, bundle) { + bundle["manifest.json"] = bundle[".vite/manifest.json"]; + bundle["manifest.json"].fileName = "manifest.json"; + delete bundle[".vite/manifest.json"]; + }, +}; + export default defineConfig((env) => ({ resolve: { alias: { @@ -14,6 +25,7 @@ export default defineConfig((env) => ({ drop: env.command === "build" ? ["console", "debugger"] : [], }, plugins: [ + viteManifestHackIssue846, react(), crx({ manifest: {