2026-05-01 20:39:09 +08:00
|
|
|
import { createRequire } from 'node:module'
|
|
|
|
|
import { fileURLToPath, URL } from 'node:url'
|
2026-04-27 00:56:33 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
|
import { visualizer } from 'rollup-plugin-visualizer'
|
|
|
|
|
import { defineConfig, loadEnv, type PluginOption } from 'vite'
|
|
|
|
|
import { compression } from 'vite-plugin-compression2'
|
2026-04-27 00:56:33 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
const r = (path: string) => fileURLToPath(new URL(path, import.meta.url))
|
|
|
|
|
const nodeRequire = createRequire(import.meta.url)
|
|
|
|
|
const resolveNodeModule = (specifier: string) => nodeRequire.resolve(specifier)
|
2026-04-01 00:58:42 +08:00
|
|
|
|
|
|
|
|
export default defineConfig(({ mode }) => {
|
2026-05-01 20:39:09 +08:00
|
|
|
const env = loadEnv(mode, '.', '')
|
|
|
|
|
const isProd = mode === 'production'
|
|
|
|
|
const analyze = env.ANALYZE === 'true'
|
2026-04-27 00:56:33 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
const plugins: PluginOption[] = [vue()]
|
2026-04-27 00:56:33 +08:00
|
|
|
|
|
|
|
|
if (isProd) {
|
|
|
|
|
plugins.push(
|
|
|
|
|
compression({
|
2026-05-01 20:39:09 +08:00
|
|
|
algorithms: ['gzip', 'brotliCompress'],
|
2026-04-27 00:56:33 +08:00
|
|
|
threshold: 1024,
|
|
|
|
|
}),
|
2026-05-01 20:39:09 +08:00
|
|
|
)
|
2026-04-27 00:56:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (analyze) {
|
|
|
|
|
plugins.push(
|
|
|
|
|
visualizer({
|
2026-05-01 20:39:09 +08:00
|
|
|
filename: 'stats.html',
|
|
|
|
|
template: 'treemap',
|
2026-04-27 00:56:33 +08:00
|
|
|
gzipSize: true,
|
|
|
|
|
brotliSize: true,
|
|
|
|
|
open: true,
|
|
|
|
|
}) as PluginOption,
|
2026-05-01 20:39:09 +08:00
|
|
|
)
|
2026-04-27 00:56:33 +08:00
|
|
|
}
|
2026-04-01 00:58:42 +08:00
|
|
|
|
|
|
|
|
return {
|
2026-04-27 00:56:33 +08:00
|
|
|
plugins,
|
2026-04-01 00:58:42 +08:00
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
2026-05-01 20:39:09 +08:00
|
|
|
'@': r('./src'),
|
|
|
|
|
'@geo/shared-types': r('../../packages/shared-types/src/index.ts'),
|
|
|
|
|
'@geo/http-client': r('../../packages/http-client/src/index.ts'),
|
|
|
|
|
'@jsquash/webp/encode.js': resolveNodeModule('@jsquash/webp/encode.js'),
|
|
|
|
|
'@jsquash/webp/codec/enc/webp_enc.wasm': resolveNodeModule(
|
|
|
|
|
'@jsquash/webp/codec/enc/webp_enc.wasm',
|
|
|
|
|
),
|
|
|
|
|
'@jsquash/webp/codec/enc/webp_enc_simd.wasm': resolveNodeModule(
|
|
|
|
|
'@jsquash/webp/codec/enc/webp_enc_simd.wasm',
|
|
|
|
|
),
|
2026-04-01 00:58:42 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
server: {
|
2026-05-01 20:39:09 +08:00
|
|
|
host: '0.0.0.0',
|
2026-04-01 00:58:42 +08:00
|
|
|
port: 5173,
|
|
|
|
|
proxy: {
|
2026-05-01 20:39:09 +08:00
|
|
|
'/api': {
|
|
|
|
|
target: env.VITE_API_PROXY_TARGET || 'http://localhost:8080',
|
2026-04-01 00:58:42 +08:00
|
|
|
changeOrigin: true,
|
2026-05-06 12:57:03 +08:00
|
|
|
ws: true,
|
2026-04-01 00:58:42 +08:00
|
|
|
},
|
2026-05-01 20:39:09 +08:00
|
|
|
'/swagger': {
|
|
|
|
|
target: env.VITE_API_PROXY_TARGET || 'http://localhost:8080',
|
2026-04-30 23:19:31 +08:00
|
|
|
changeOrigin: true,
|
|
|
|
|
},
|
2026-04-01 00:58:42 +08:00
|
|
|
},
|
|
|
|
|
},
|
2026-05-01 20:39:09 +08:00
|
|
|
esbuild: isProd ? { drop: ['console', 'debugger'] } : undefined,
|
2026-04-27 00:56:33 +08:00
|
|
|
build: {
|
2026-05-01 20:39:09 +08:00
|
|
|
target: 'es2022',
|
|
|
|
|
sourcemap: 'hidden',
|
2026-04-27 00:56:33 +08:00
|
|
|
cssCodeSplit: true,
|
|
|
|
|
assetsInlineLimit: 4096,
|
|
|
|
|
chunkSizeWarningLimit: 800,
|
|
|
|
|
reportCompressedSize: false,
|
|
|
|
|
modulePreload: { polyfill: false },
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
output: {
|
2026-05-01 20:39:09 +08:00
|
|
|
entryFileNames: 'assets/js/[name]-[hash].js',
|
|
|
|
|
chunkFileNames: 'assets/js/[name]-[hash].js',
|
2026-04-27 00:56:33 +08:00
|
|
|
assetFileNames: (info) => {
|
2026-05-01 20:39:09 +08:00
|
|
|
const name = info.names?.[0] ?? ''
|
2026-04-27 00:56:33 +08:00
|
|
|
if (/\.(png|jpe?g|gif|svg|webp|avif|ico)$/i.test(name)) {
|
2026-05-01 20:39:09 +08:00
|
|
|
return 'assets/img/[name]-[hash][extname]'
|
2026-04-27 00:56:33 +08:00
|
|
|
}
|
|
|
|
|
if (/\.(woff2?|eot|ttf|otf)$/i.test(name)) {
|
2026-05-01 20:39:09 +08:00
|
|
|
return 'assets/fonts/[name]-[hash][extname]'
|
2026-04-27 00:56:33 +08:00
|
|
|
}
|
|
|
|
|
if (/\.css$/i.test(name)) {
|
2026-05-01 20:39:09 +08:00
|
|
|
return 'assets/css/[name]-[hash][extname]'
|
2026-04-27 00:56:33 +08:00
|
|
|
}
|
2026-05-01 20:39:09 +08:00
|
|
|
return 'assets/[name]-[hash][extname]'
|
2026-04-27 00:56:33 +08:00
|
|
|
},
|
|
|
|
|
manualChunks(id) {
|
2026-05-01 20:39:09 +08:00
|
|
|
if (!id.includes('node_modules')) return undefined
|
2026-04-27 00:56:33 +08:00
|
|
|
|
|
|
|
|
// Milkdown editor and its heavy companion deps (only the editor route
|
|
|
|
|
// imports them, so this chunk stays lazy-loaded).
|
|
|
|
|
if (
|
2026-05-01 20:39:09 +08:00
|
|
|
id.includes('/@milkdown/') ||
|
|
|
|
|
id.includes('/prosemirror-') ||
|
|
|
|
|
id.includes('/codemirror/') ||
|
|
|
|
|
id.includes('/@codemirror/') ||
|
|
|
|
|
id.includes('/@lezer/') ||
|
|
|
|
|
id.includes('/katex/') ||
|
|
|
|
|
id.includes('/micromark') ||
|
|
|
|
|
id.includes('/mdast-util') ||
|
|
|
|
|
id.includes('/unist-util') ||
|
|
|
|
|
id.includes('/hast-util') ||
|
|
|
|
|
id.includes('/unified/') ||
|
|
|
|
|
id.includes('/remark') ||
|
|
|
|
|
id.includes('/rehype') ||
|
|
|
|
|
id.includes('/decode-named-character-reference/') ||
|
|
|
|
|
id.includes('/vfile') ||
|
|
|
|
|
id.includes('/zwitch/') ||
|
|
|
|
|
id.includes('/longest-streak/') ||
|
|
|
|
|
id.includes('/bail/') ||
|
|
|
|
|
id.includes('/extend/') ||
|
|
|
|
|
id.includes('/devlop/') ||
|
|
|
|
|
id.includes('/is-plain-obj/') ||
|
|
|
|
|
id.includes('/trough/') ||
|
|
|
|
|
id.includes('/ccount/') ||
|
|
|
|
|
id.includes('/escape-string-regexp/') ||
|
|
|
|
|
id.includes('/markdown-table/') ||
|
|
|
|
|
id.includes('/@marijn/') ||
|
|
|
|
|
id.includes('/orderedmap/') ||
|
|
|
|
|
id.includes('/w3c-keyname/') ||
|
|
|
|
|
id.includes('/rope-sequence/') ||
|
|
|
|
|
id.includes('/style-mod/') ||
|
|
|
|
|
id.includes('/crelt/') ||
|
|
|
|
|
id.includes('/@floating-ui/') ||
|
|
|
|
|
id.includes('/clsx/') ||
|
|
|
|
|
id.includes('/@ocavue/')
|
2026-04-27 00:56:33 +08:00
|
|
|
) {
|
2026-05-01 20:39:09 +08:00
|
|
|
return 'milkdown'
|
2026-04-27 00:56:33 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
if (id.includes('/nanoid/')) {
|
|
|
|
|
return 'nanoid'
|
2026-05-01 13:38:11 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
if (id.includes('/ant-design-vue/') || id.includes('/@ant-design/')) {
|
|
|
|
|
return 'antd'
|
2026-04-27 00:56:33 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
if (id.includes('/@tanstack/') || id.includes('/@vueuse/')) {
|
|
|
|
|
return 'query'
|
2026-04-27 00:56:33 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
if (id.includes('/@jsquash/')) {
|
|
|
|
|
return 'imaging'
|
2026-04-27 00:56:33 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
if (id.includes('/lodash') || id.includes('/dayjs')) {
|
|
|
|
|
return 'utils'
|
2026-04-27 00:56:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
2026-05-01 20:39:09 +08:00
|
|
|
id.includes('/markdown-it') ||
|
|
|
|
|
id.includes('/dompurify') ||
|
|
|
|
|
id.includes('/entities/') ||
|
|
|
|
|
id.includes('/mdurl/') ||
|
|
|
|
|
id.includes('/uc.micro/') ||
|
|
|
|
|
id.includes('/linkify-it/') ||
|
|
|
|
|
id.includes('/punycode.js/')
|
2026-04-27 00:56:33 +08:00
|
|
|
) {
|
2026-05-01 20:39:09 +08:00
|
|
|
return 'editor-utils'
|
2026-04-27 00:56:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
2026-05-01 20:39:09 +08:00
|
|
|
id.includes('/vue/') ||
|
|
|
|
|
id.includes('/@vue/') ||
|
|
|
|
|
id.includes('/vue-router/') ||
|
|
|
|
|
id.includes('/vue-i18n/') ||
|
|
|
|
|
id.includes('/@intlify/') ||
|
|
|
|
|
id.includes('/pinia/')
|
2026-04-27 00:56:33 +08:00
|
|
|
) {
|
2026-05-01 20:39:09 +08:00
|
|
|
return 'vue-vendor'
|
2026-04-27 00:56:33 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
return 'vendor'
|
2026-04-27 00:56:33 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-05-01 20:39:09 +08:00
|
|
|
}
|
|
|
|
|
})
|