| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import { sentryVitePlugin } from "@sentry/vite-plugin"
- import { defineConfig } from "electron-vite"
- import appPlugin from "@kirincode-ai/app/vite"
- import * as fs from "node:fs/promises"
- const KIRINCODE_SERVER_DIST = "../kirincode/dist/node"
- const channel = (() => {
- const raw = process.env.KIRINCODE_CHANNEL
- if (raw === "dev" || raw === "beta" || raw === "prod") return raw
- if (process.env.KIRINCODE_CHANNEL === "latest") return "prod"
- return "dev"
- })()
- const sentry =
- process.env.SENTRY_AUTH_TOKEN && process.env.SENTRY_ORG && process.env.SENTRY_PROJECT
- ? sentryVitePlugin({
- authToken: process.env.SENTRY_AUTH_TOKEN,
- org: process.env.SENTRY_ORG,
- project: process.env.SENTRY_PROJECT,
- telemetry: false,
- release: {
- name: process.env.SENTRY_RELEASE ?? process.env.VITE_SENTRY_RELEASE,
- },
- sourcemaps: {
- assets: "./out/renderer/**",
- filesToDeleteAfterUpload: "./out/renderer/**/*.map",
- },
- })
- : false
- export default defineConfig({
- main: {
- define: {
- "import.meta.env.KIRINCODE_CHANNEL": JSON.stringify(channel),
- },
- build: {
- rollupOptions: {
- input: { index: "src/main/index.ts", sidecar: "src/main/sidecar.ts", "admin-server": "src/main/admin-server.ts" },
- // Keep this identical to electron-vite's Node 20.11+ shim. Its regex insertion can
- // corrupt bundled TypeScript, while a Rollup banner places the shim safely.
- output: {
- banner: `
- // -- CommonJS Shims --
- import __cjs_mod__ from 'node:module';
- const __filename = import.meta.filename;
- const __dirname = import.meta.dirname;
- const require = __cjs_mod__.createRequire(import.meta.url);
- `,
- },
- },
- externalizeDeps: { include: ["@lydell/node-pty"] },
- },
- plugins: [
- {
- name: "kirincode:virtual-server-module",
- enforce: "pre",
- resolveId(id) {
- if (id === "virtual:kirincode-server") return this.resolve(`${KIRINCODE_SERVER_DIST}/node.js`)
- },
- },
- {
- name: "kirincode:copy-server-assets",
- async writeBundle() {
- for (const l of await fs.readdir(KIRINCODE_SERVER_DIST)) {
- if (!l.endsWith(".wasm")) continue
- await fs.writeFile(`./out/main/chunks/${l}`, await fs.readFile(`${KIRINCODE_SERVER_DIST}/${l}`))
- }
- },
- },
- ],
- },
- preload: {
- build: {
- rollupOptions: {
- input: { index: "src/preload/index.ts" },
- output: {
- format: "cjs",
- entryFileNames: "[name].js",
- },
- },
- },
- },
- renderer: {
- plugins: [appPlugin, sentry],
- publicDir: "../../../app/public",
- root: "src/renderer",
- build: {
- sourcemap: true,
- rollupOptions: {
- input: {
- main: "src/renderer/index.html",
- },
- },
- },
- },
- })
|