Makelore 2.0 initial clean snapshot
This commit is contained in:
102
vite.config.ts
Normal file
102
vite.config.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import electron from 'vite-plugin-electron';
|
||||
import renderer from 'vite-plugin-electron-renderer';
|
||||
import { resolve } from 'path';
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
|
||||
function getExtensionPackages(): Set<string> {
|
||||
try {
|
||||
const manifestPath = resolve(__dirname, 'niancode-extensions.json');
|
||||
if (!existsSync(manifestPath)) return new Set();
|
||||
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
||||
const allIds: string[] = [
|
||||
...(manifest.extensions?.main ?? []),
|
||||
...(manifest.extensions?.renderer ?? []),
|
||||
];
|
||||
const pkgs = new Set<string>();
|
||||
for (const id of allIds) {
|
||||
if (id.startsWith('builtin/')) continue;
|
||||
const parts = id.split('/');
|
||||
pkgs.add(parts[0].startsWith('@') ? parts.slice(0, 2).join('/') : parts[0]);
|
||||
}
|
||||
return pkgs;
|
||||
} catch {
|
||||
return new Set();
|
||||
}
|
||||
}
|
||||
|
||||
const extensionPackages = getExtensionPackages();
|
||||
const rendererOnly = process.env.NIANCODE_RENDERER_ONLY === '1';
|
||||
|
||||
function isMainProcessExternal(id: string): boolean {
|
||||
if (!id || id.startsWith('\0')) return false;
|
||||
if (id.startsWith('.') || id.startsWith('/') || /^[A-Za-z]:[\\/]/.test(id)) return false;
|
||||
if (id.startsWith('@/') || id.startsWith('@electron/')) return false;
|
||||
for (const pkg of extensionPackages) {
|
||||
if (id === pkg || id.startsWith(pkg + '/')) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
// Required for Electron: all asset URLs must be relative because the renderer
|
||||
// loads via file:// in production. vite-plugin-electron-renderer sets this
|
||||
// automatically, but we declare it explicitly so the intent is clear and the
|
||||
// build remains correct even if plugin order ever changes.
|
||||
base: './',
|
||||
define: {
|
||||
__NIANCODE_RENDERER_ONLY__: JSON.stringify(rendererOnly),
|
||||
},
|
||||
plugins: [
|
||||
react(),
|
||||
!rendererOnly && electron([
|
||||
{
|
||||
// Main process entry file
|
||||
entry: 'electron/main/index.ts',
|
||||
onstart(options) {
|
||||
options.startup();
|
||||
},
|
||||
vite: {
|
||||
build: {
|
||||
outDir: 'dist-electron/main',
|
||||
rollupOptions: {
|
||||
external: isMainProcessExternal,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// Preload scripts entry file
|
||||
entry: 'electron/preload/index.ts',
|
||||
onstart(options) {
|
||||
options.reload();
|
||||
},
|
||||
vite: {
|
||||
build: {
|
||||
outDir: 'dist-electron/preload',
|
||||
rollupOptions: {
|
||||
external: ['electron'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
]),
|
||||
!rendererOnly && renderer(),
|
||||
].filter(Boolean),
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve(__dirname, 'src'),
|
||||
'@electron': resolve(__dirname, 'electron'),
|
||||
},
|
||||
dedupe: ['react', 'react-dom', 'react-i18next', 'zustand', 'sonner', 'lucide-react'],
|
||||
},
|
||||
server: {
|
||||
port: 5173,
|
||||
},
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
emptyOutDir: true,
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user