Files
page-agent/packages/website/vite.config.js
T

107 lines
3.2 KiB
JavaScript
Raw Normal View History

2025-12-01 20:11:12 +08:00
import tailwindcss from '@tailwindcss/vite'
2026-04-28 15:33:11 +08:00
import react from '@vitejs/plugin-react'
2025-12-17 15:27:15 +08:00
import { config as dotenvConfig } from 'dotenv'
2026-03-12 20:01:00 +08:00
import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
2025-12-01 20:11:12 +08:00
import process from 'node:process'
import { dirname, join, resolve } from 'path'
2025-12-01 20:11:12 +08:00
import { fileURLToPath } from 'url'
import { defineConfig } from 'vite'
const __dirname = dirname(fileURLToPath(import.meta.url))
const pageAgentPkg = JSON.parse(
readFileSync(resolve(__dirname, '../page-agent/package.json'), 'utf-8')
)
2025-12-01 20:11:12 +08:00
2025-12-17 15:27:15 +08:00
// Load .env from repo root
2026-03-17 00:29:13 +08:00
dotenvConfig({ path: resolve(__dirname, '../../.env'), quiet: true })
2025-12-17 15:27:15 +08:00
// All SPA routes that need index.html copies for direct access on static hosts
const SPA_ROUTES = [
'docs',
'docs/introduction/overview',
'docs/introduction/quick-start',
'docs/introduction/limitations',
'docs/introduction/troubleshooting',
'docs/features/custom-tools',
'docs/features/data-masking',
'docs/features/custom-instructions',
'docs/features/models',
2026-04-04 01:15:41 +08:00
'docs/features/local-llms',
'docs/features/chrome-extension',
2026-03-22 03:21:33 +08:00
'docs/features/mcp-server',
'docs/features/third-party-agent',
'docs/advanced/page-agent',
'docs/advanced/page-agent-core',
'docs/advanced/page-controller',
'docs/advanced/custom-ui',
'docs/advanced/security-permissions',
]
2026-03-12 20:01:00 +08:00
const SITE_URL = 'https://alibaba.github.io/page-agent'
function spaRoutes() {
return {
name: 'spa-routes',
closeBundle() {
const dist = resolve(__dirname, 'dist')
const src = join(dist, 'index.html')
for (const route of SPA_ROUTES) {
const dir = join(dist, route)
mkdirSync(dir, { recursive: true })
copyFileSync(src, join(dir, 'index.html'))
}
console.log(` ✓ Copied index.html to ${SPA_ROUTES.length} SPA routes`)
2026-03-12 20:01:00 +08:00
const today = new Date().toISOString().split('T')[0]
const urls = ['', ...SPA_ROUTES]
.map(
(route) =>
` <url>\n <loc>${SITE_URL}/${route}</loc>\n <lastmod>${today}</lastmod>\n </url>`
)
.join('\n')
writeFileSync(
join(dist, 'sitemap.xml'),
`<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls}\n</urlset>\n`
)
console.log(` ✓ Generated sitemap.xml with ${SPA_ROUTES.length + 1} URLs`)
},
}
}
2025-12-01 20:11:12 +08:00
// Website Config (React Documentation Site)
2026-01-16 19:04:26 +08:00
export default defineConfig(({ mode }) => ({
2026-02-27 19:46:44 +08:00
base: '/page-agent/',
2025-12-01 20:11:12 +08:00
clearScreen: false,
plugins: [react(), tailwindcss(), spaRoutes()],
2026-01-16 14:50:56 +08:00
build: {
2026-01-16 15:09:30 +08:00
chunkSizeWarningLimit: 2000,
2026-01-16 14:50:56 +08:00
cssCodeSplit: true,
rollupOptions: {
onwarn: function (message, handler) {
if (message.code === 'EVAL') return
handler(message)
},
2026-03-03 21:05:16 +08:00
output: {
2026-04-28 14:42:34 +08:00
manualChunks(id) {
if (/[\\/]node_modules[\\/](react|react-dom|wouter)([\\/]|$)/.test(id)) {
return 'vendor'
}
2026-03-03 21:05:16 +08:00
},
},
2026-01-16 14:50:56 +08:00
},
},
2025-12-01 20:11:12 +08:00
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
define: {
2026-01-16 19:04:26 +08:00
...(mode === 'development' && {
'import.meta.env.LLM_MODEL_NAME': JSON.stringify(process.env.LLM_MODEL_NAME),
'import.meta.env.LLM_API_KEY': JSON.stringify(process.env.LLM_API_KEY),
'import.meta.env.LLM_BASE_URL': JSON.stringify(process.env.LLM_BASE_URL),
}),
'import.meta.env.VERSION': JSON.stringify(pageAgentPkg.version),
2025-12-01 20:11:12 +08:00
},
2026-01-16 19:04:26 +08:00
}))