mirror of
https://github.com/ilyhalight/voice-over-translation.git
synced 2026-10-19 07:43:33 +00:00
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import path from "node:path";
|
|
import { crx } from "@crxjs/vite-plugin";
|
|
import { defineConfig, type Plugin, type UserConfig } from "vite";
|
|
import { type BuildConfig, buildDefine, getBuildConfig } from "./lib/env";
|
|
import {
|
|
finalizeChromeBuild,
|
|
getChromeExtensionBuildEnv,
|
|
} from "./lib/extension/chrome-postbuild";
|
|
import manifest from "./lib/extension/manifest.config";
|
|
import { distExtDir } from "./lib/paths";
|
|
import { createBaseViteConfig } from "./lib/vite-base-config";
|
|
|
|
function chromePackagePlugin(
|
|
config: BuildConfig,
|
|
headers: {
|
|
version?: string;
|
|
author?: string;
|
|
},
|
|
): Plugin {
|
|
return {
|
|
name: "vot-chrome-package",
|
|
apply: "build",
|
|
enforce: "post",
|
|
async closeBundle() {
|
|
await finalizeChromeBuild(config, headers);
|
|
},
|
|
};
|
|
}
|
|
|
|
export default defineConfig(async ({ mode }) => {
|
|
const buildConfig = getBuildConfig(mode);
|
|
const baseConfig = createBaseViteConfig({ cacheName: "chrome-extension" });
|
|
const { headers, locales, branch } =
|
|
await getChromeExtensionBuildEnv(buildConfig);
|
|
|
|
return {
|
|
...baseConfig,
|
|
plugins: [
|
|
...(baseConfig.plugins ?? []),
|
|
crx({ manifest }),
|
|
chromePackagePlugin(buildConfig, headers),
|
|
],
|
|
define: buildDefine({
|
|
debug: false,
|
|
isExtension: true,
|
|
availableLocales: locales,
|
|
repoBranch: branch,
|
|
version: String(headers.version || ""),
|
|
authors: String(headers.author || ""),
|
|
crxjsBuild: true,
|
|
}),
|
|
server: {
|
|
cors: {
|
|
origin: [/chrome-extension:\/\//],
|
|
},
|
|
},
|
|
build: {
|
|
...baseConfig.build,
|
|
outDir: path.join(distExtDir, "chrome"),
|
|
emptyOutDir: true,
|
|
sourcemap: false,
|
|
minify: "oxc",
|
|
},
|
|
} satisfies UserConfig;
|
|
});
|