| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import { fileURLToPath, URL } from 'node:url'
- import { defineConfig, loadEnv } from 'vite'
- import { createVitePlugins } from './vitePlugins.config'
- import { createProxy } from './viteProxy.config'
- import type { ImportMetaEnv } from './env'
- // https://vite.dev/config/
- export default defineConfig(({ mode }) => {
- const rawEnv = loadEnv(mode, process.cwd())
- console.log({ mode, rawEnv })
- const env: ImportMetaEnv = {
- VITE_GLOB_APP_TITLE: rawEnv.VITE_GLOB_APP_TITLE || 'FranklinWH Toolbox',
- VITE_GLOB_APP_NAME: rawEnv.VITE_GLOB_APP_NAME || 'FWH Toolbox',
- VITE_USER_NODE_ENV: rawEnv.VITE_USER_NODE_ENV || 'development',
- VITE_PUBLIC_PATH: rawEnv.VITE_PUBLIC_PATH || '/',
- VITE_ROUTER_MODE: rawEnv.VITE_ROUTER_MODE || 'hash',
- VITE_API_URL: rawEnv.VITE_API_URL || '/fwh-toolbox/api',
- // 仅development环境生效
- VITE_PORT: rawEnv.VITE_PORT,
- VITE_OPEN: rawEnv.VITE_OPEN,
- VITE_DEVTOOLS: rawEnv.VITE_DEVTOOLS,
- VITE_CODEINSPECTOR: rawEnv.VITE_CODEINSPECTOR,
- // 仅production打包
- VITE_REPORT: rawEnv.VITE_REPORT,
- VITE_DROP_CONSOLE: rawEnv.VITE_DROP_CONSOLE,
- VITE_BUILD_COMPRESS: rawEnv.VITE_BUILD_COMPRESS,
- VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE: rawEnv.VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE,
- }
- return {
- base: env.VITE_PUBLIC_PATH,
- plugins: createVitePlugins(env),
- resolve: {
- alias: {
- '@': fileURLToPath(new URL('./src', import.meta.url)),
- },
- },
- server: {
- host: '0.0.0.0',
- port: env.VITE_PORT ? Number(env.VITE_PORT) : undefined,
- open: env.VITE_OPEN === 'true',
- cors: true,
- // Load proxy configuration from .env.development
- proxy: createProxy(env.VITE_PUBLIC_PATH, true),
- allowedHosts: true,
- },
- build: {
- sourcemap: true, // ✅ 生成 source map
- rolldownOptions: {
- output: {
-
- // advancedChunks: {
- // includeDependenciesRecursively: true,
- // minSize: 50 * 1024, // 全局最小 50KB
- // maxSize: 300 * 1024, // 全局最大 300KB
- // minShareCount: 1,
- // groups: [
- // {
- // name: 'vue',
- // test: /node_modules[\\/]vue/,
- // priority: 10,
- // },
- // {
- // name: 'g2',
- // test: /node_modules[\\/]@antv[\\/]g2/,
- // priority: 9,
- // },
- // {
- // name: 'g-webgl',
- // test: /node_modules[\\/]@antv[\\/]g-webgl/,
- // priority: 9,
- // },
- // {
- // name: 'naive-ui',
- // test: /node_modules[\\/]naive-ui/,
- // priority: 8,
- // },
- // {
- // name: 'icons',
- // test: /node_modules[\\/]@iconify-json[\\/]/,
- // priority: 7,
- // },
- // {
- // name: 'utils',
- // test: /node_modules[\\/](dayjs|chroma-js|uuid|@vueuse)/,
- // priority: 6,
- // },
- // {
- // name: (id) =>
- // id.includes('src/components/fullScreenCanvas') ? 'fullScreenCanvas' : null,
- // test: (id) => id.includes('src/components/fullScreenCanvas'),
- // priority: 5,
- // },
- // {
- // name: 'vendor', // fallback
- // test: /node_modules/,
- // priority: 1,
- // },
- // ],
- // },
- },
- },
- },
- }
- })
|