2026-02-28 00:01:01 +08:00
|
|
|
import { resolve } from 'node:path';
|
|
|
|
|
|
|
|
|
|
import type { PluginOption, ViteDevServer } from 'vite';
|
|
|
|
|
import { defineConfig, loadEnv } from 'vite';
|
|
|
|
|
import { VitePWA } from 'vite-plugin-pwa';
|
|
|
|
|
|
2026-03-01 20:58:05 +08:00
|
|
|
import { viteEnvRestartKeys } from './plugins/vite/envRestartKeys';
|
2026-02-28 00:01:01 +08:00
|
|
|
import {
|
|
|
|
|
sharedOptimizeDeps,
|
|
|
|
|
sharedRendererDefine,
|
|
|
|
|
sharedRendererPlugins,
|
|
|
|
|
sharedRollupOutput,
|
|
|
|
|
} from './plugins/vite/sharedRendererConfig';
|
2026-03-04 21:47:31 +08:00
|
|
|
import { vercelSkewProtection } from './plugins/vite/vercelSkewProtection';
|
2026-02-28 00:01:01 +08:00
|
|
|
|
|
|
|
|
const isMobile = process.env.MOBILE === 'true';
|
|
|
|
|
const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';
|
|
|
|
|
|
|
|
|
|
Object.assign(process.env, loadEnv(mode, process.cwd(), ''));
|
|
|
|
|
|
|
|
|
|
const isDev = process.env.NODE_ENV !== 'production';
|
|
|
|
|
const platform = isMobile ? 'mobile' : 'web';
|
|
|
|
|
|
|
|
|
|
export default defineConfig({
|
2026-03-30 21:54:20 +08:00
|
|
|
base: isDev ? '/' : process.env.VITE_CDN_BASE || '/_spa/',
|
2026-02-28 00:01:01 +08:00
|
|
|
build: {
|
|
|
|
|
outDir: isMobile ? 'dist/mobile' : 'dist/desktop',
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
input: resolve(__dirname, isMobile ? 'index.mobile.html' : 'index.html'),
|
|
|
|
|
output: sharedRollupOutput,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
define: sharedRendererDefine({ isMobile, isElectron: false }),
|
|
|
|
|
optimizeDeps: sharedOptimizeDeps,
|
|
|
|
|
plugins: [
|
2026-03-04 21:47:31 +08:00
|
|
|
vercelSkewProtection(),
|
2026-03-01 20:58:05 +08:00
|
|
|
viteEnvRestartKeys(['APP_URL']),
|
2026-02-28 00:01:01 +08:00
|
|
|
...sharedRendererPlugins({ platform }),
|
|
|
|
|
|
|
|
|
|
isDev && {
|
|
|
|
|
name: 'lobe-dev-proxy-print',
|
|
|
|
|
configureServer(server: ViteDevServer) {
|
|
|
|
|
const ONLINE_HOST = 'https://app.lobehub.com';
|
2026-03-03 18:50:57 +08:00
|
|
|
const c = {
|
|
|
|
|
green: (s: string) => `\x1B[32m${s}\x1B[0m`,
|
|
|
|
|
bold: (s: string) => `\x1B[1m${s}\x1B[0m`,
|
|
|
|
|
cyan: (s: string) => `\x1B[36m${s}\x1B[0m`,
|
|
|
|
|
};
|
|
|
|
|
const { info } = server.config.logger;
|
|
|
|
|
return () => {
|
|
|
|
|
server.printUrls = () => {
|
|
|
|
|
const urls = server.resolvedUrls;
|
|
|
|
|
if (!urls?.local?.[0]) return;
|
|
|
|
|
const localHost = urls.local[0].replace(/\/$/, '');
|
|
|
|
|
const proxyUrl = `${ONLINE_HOST}/_dangerous_local_dev_proxy?debug-host=${encodeURIComponent(localHost)}`;
|
|
|
|
|
const colorUrl = (url: string) =>
|
|
|
|
|
c.cyan(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
|
|
|
|
|
info(` ${c.green('➜')} ${c.bold('Debug Proxy')}: ${colorUrl(proxyUrl)}`);
|
|
|
|
|
};
|
|
|
|
|
};
|
2026-02-28 00:01:01 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
VitePWA({
|
|
|
|
|
injectRegister: null,
|
|
|
|
|
manifest: false,
|
|
|
|
|
registerType: 'prompt',
|
|
|
|
|
workbox: {
|
|
|
|
|
globPatterns: ['**/*.{js,css,html,woff2}'],
|
|
|
|
|
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024,
|
|
|
|
|
runtimeCaching: [
|
|
|
|
|
{
|
|
|
|
|
handler: 'StaleWhileRevalidate',
|
|
|
|
|
options: { cacheName: 'google-fonts-stylesheets' },
|
|
|
|
|
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
handler: 'CacheFirst',
|
|
|
|
|
options: {
|
|
|
|
|
cacheName: 'google-fonts-webfonts',
|
|
|
|
|
expiration: { maxAgeSeconds: 60 * 60 * 24 * 365, maxEntries: 30 },
|
|
|
|
|
},
|
|
|
|
|
urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
handler: 'StaleWhileRevalidate',
|
|
|
|
|
options: {
|
|
|
|
|
cacheName: 'image-assets',
|
|
|
|
|
expiration: { maxAgeSeconds: 60 * 60 * 24 * 30, maxEntries: 100 },
|
|
|
|
|
},
|
|
|
|
|
urlPattern: /\.(?:png|jpg|jpeg|svg|gif|webp|ico|avif)$/i,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
handler: 'NetworkFirst',
|
|
|
|
|
options: {
|
|
|
|
|
cacheName: 'api-cache',
|
|
|
|
|
expiration: { maxAgeSeconds: 60 * 5, maxEntries: 50 },
|
|
|
|
|
},
|
|
|
|
|
urlPattern: /\/(api|trpc)\/.*/i,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
].filter(Boolean) as PluginOption[],
|
|
|
|
|
|
|
|
|
|
server: {
|
|
|
|
|
cors: true,
|
|
|
|
|
port: 9876,
|
2026-02-28 15:00:17 +08:00
|
|
|
host: true,
|
2026-02-28 00:01:01 +08:00
|
|
|
proxy: {
|
2026-03-26 16:52:35 +08:00
|
|
|
'/api': `http://localhost:${process.env.PORT || 3010}`,
|
|
|
|
|
'/oidc': `http://localhost:${process.env.PORT || 3010}`,
|
|
|
|
|
'/trpc': `http://localhost:${process.env.PORT || 3010}`,
|
|
|
|
|
'/webapi': `http://localhost:${process.env.PORT || 3010}`,
|
2026-02-28 00:01:01 +08:00
|
|
|
},
|
|
|
|
|
warmup: {
|
2026-03-01 18:35:38 +08:00
|
|
|
clientFiles: [
|
2026-03-13 22:17:36 +08:00
|
|
|
// src/ business code
|
|
|
|
|
'./src/initialize.ts',
|
|
|
|
|
'./src/spa/**/*.tsx',
|
|
|
|
|
'./src/business/**/*.{ts,tsx}',
|
|
|
|
|
'./src/components/**/*.{ts,tsx}',
|
|
|
|
|
'./src/config/**/*.ts',
|
|
|
|
|
'./src/const/**/*.ts',
|
|
|
|
|
'./src/envs/**/*.ts',
|
|
|
|
|
'./src/features/**/*.{ts,tsx}',
|
|
|
|
|
'./src/helpers/**/*.ts',
|
|
|
|
|
'./src/hooks/**/*.{ts,tsx}',
|
|
|
|
|
'./src/layout/**/*.{ts,tsx}',
|
|
|
|
|
'./src/libs/**/*.{ts,tsx}',
|
|
|
|
|
'./src/locales/**/*.ts',
|
|
|
|
|
'./src/routes/**/*.{ts,tsx}',
|
|
|
|
|
'./src/services/**/*.ts',
|
|
|
|
|
'./src/store/**/*.{ts,tsx}',
|
|
|
|
|
'./src/styles/**/*.ts',
|
|
|
|
|
'./src/utils/**/*.{ts,tsx}',
|
|
|
|
|
|
|
|
|
|
// monorepo packages
|
|
|
|
|
'./packages/types/src/**/*.ts',
|
|
|
|
|
'./packages/const/src/**/*.ts',
|
|
|
|
|
'./packages/utils/src/**/*.ts',
|
|
|
|
|
'./packages/context-engine/src/**/*.ts',
|
|
|
|
|
'./packages/prompts/src/**/*.ts',
|
|
|
|
|
'./packages/model-bank/src/**/*.ts',
|
|
|
|
|
'./packages/model-runtime/src/**/*.ts',
|
|
|
|
|
'./packages/agent-runtime/src/**/*.ts',
|
|
|
|
|
'./packages/conversation-flow/src/**/*.ts',
|
|
|
|
|
'./packages/electron-client-ipc/src/**/*.ts',
|
|
|
|
|
'./packages/builtin-agents/src/**/*.ts',
|
|
|
|
|
'./packages/builtin-skills/src/**/*.ts',
|
|
|
|
|
'./packages/builtin-tool-*/src/**/*.ts',
|
|
|
|
|
'./packages/builtin-tools/src/**/*.ts',
|
|
|
|
|
'./packages/business/*/src/**/*.ts',
|
|
|
|
|
'./packages/config/src/**/*.ts',
|
|
|
|
|
'./packages/edge-config/src/**/*.ts',
|
|
|
|
|
'./packages/editor-runtime/src/**/*.ts',
|
|
|
|
|
'./packages/fetch-sse/src/**/*.ts',
|
|
|
|
|
'./packages/desktop-bridge/src/**/*.ts',
|
|
|
|
|
'./packages/python-interpreter/src/**/*.ts',
|
|
|
|
|
'./packages/agent-manager-runtime/src/**/*.ts',
|
2026-03-01 18:35:38 +08:00
|
|
|
],
|
2026-02-28 00:01:01 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|