2023-12-14 21:45:29 +08:00
|
|
|
import process from 'node:process';
|
|
|
|
import { URL, fileURLToPath } from 'node:url';
|
2021-11-29 09:19:15 +08:00
|
|
|
import { defineConfig, loadEnv } from 'vite';
|
2023-11-17 08:45:00 +08:00
|
|
|
import { setupVitePlugins } from './build/plugins';
|
2024-06-13 23:59:30 +08:00
|
|
|
import { createViteProxy, getBuildTime } from './build/config';
|
2021-05-28 00:32:34 +08:00
|
|
|
|
2022-04-01 14:47:57 +08:00
|
|
|
export default defineConfig(configEnv => {
|
2023-11-17 08:45:00 +08:00
|
|
|
const viteEnv = loadEnv(configEnv.mode, process.cwd()) as unknown as Env.ImportMeta;
|
2022-04-27 22:27:46 +08:00
|
|
|
|
2024-06-13 23:59:30 +08:00
|
|
|
const buildTime = getBuildTime();
|
2024-01-18 23:43:33 +08:00
|
|
|
|
2024-08-14 10:25:30 +08:00
|
|
|
const enableProxy = configEnv.command === 'serve' && !configEnv.isPreview;
|
|
|
|
|
2021-11-29 09:19:15 +08:00
|
|
|
return {
|
2022-03-05 01:55:21 +08:00
|
|
|
base: viteEnv.VITE_BASE_URL,
|
2021-11-29 09:19:15 +08:00
|
|
|
resolve: {
|
|
|
|
alias: {
|
2023-11-17 08:45:00 +08:00
|
|
|
'~': fileURLToPath(new URL('./', import.meta.url)),
|
|
|
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
2022-04-01 14:47:57 +08:00
|
|
|
}
|
2021-11-29 09:19:15 +08:00
|
|
|
},
|
|
|
|
css: {
|
|
|
|
preprocessorOptions: {
|
|
|
|
scss: {
|
2024-09-21 08:34:38 +08:00
|
|
|
api: 'modern-compiler',
|
|
|
|
additionalData: `@use "@/styles/scss/global.scss" as *;`
|
2022-04-01 14:47:57 +08:00
|
|
|
}
|
|
|
|
}
|
2021-11-29 09:19:15 +08:00
|
|
|
},
|
2024-06-06 20:08:00 +08:00
|
|
|
plugins: setupVitePlugins(viteEnv, buildTime),
|
2023-11-17 08:45:00 +08:00
|
|
|
define: {
|
2024-01-18 23:43:33 +08:00
|
|
|
BUILD_TIME: JSON.stringify(buildTime)
|
2023-11-17 08:45:00 +08:00
|
|
|
},
|
2021-11-29 09:19:15 +08:00
|
|
|
server: {
|
2021-11-29 10:57:29 +08:00
|
|
|
host: '0.0.0.0',
|
2023-11-17 08:45:00 +08:00
|
|
|
port: 9527,
|
2022-03-12 16:21:40 +08:00
|
|
|
open: true,
|
2024-12-16 16:16:08 +08:00
|
|
|
proxy: createViteProxy(viteEnv, enableProxy)
|
2022-01-04 13:53:07 +08:00
|
|
|
},
|
2023-11-17 08:45:00 +08:00
|
|
|
preview: {
|
|
|
|
port: 9725
|
2022-08-03 22:25:04 +08:00
|
|
|
},
|
2022-01-04 13:53:07 +08:00
|
|
|
build: {
|
2022-06-19 15:34:18 +08:00
|
|
|
reportCompressedSize: false,
|
2023-11-17 08:45:00 +08:00
|
|
|
sourcemap: viteEnv.VITE_SOURCE_MAP === 'Y',
|
2022-05-31 23:02:24 +08:00
|
|
|
commonjsOptions: {
|
|
|
|
ignoreTryCatch: false
|
|
|
|
}
|
2022-04-01 14:47:57 +08:00
|
|
|
}
|
2021-11-29 09:19:15 +08:00
|
|
|
};
|
2021-05-28 02:22:49 +08:00
|
|
|
});
|