Files
vue-ts-example-2025/vite.config.ts
严浩 d6e05a8b44
Some checks failed
CI/CD Pipeline / build-and-deploy (push) Has been cancelled
CI/CD Pipeline / playwright (push) Has been cancelled
feat(vite.config): 添加 CI 环境变量日志输出
2025-10-30 22:32:53 +08:00

59 lines
1.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { fileURLToPath, URL } from 'node:url';
import { createViteProxy } from 'utils4u/vite';
import { defineConfig, loadEnv } from 'vite';
import { loadPlugins } from './vite-plugins/_loadPlugins';
import { optimizeDeps } from './vite.config.optimizeDeps';
import { viteConfigRollupOptions } from './vite.config.rollup';
import consola from 'consola';
// https://vite.dev/config/
export default defineConfig(async (configEnv) => {
consola.info(`[vite.config.ts] mode: ${configEnv.mode}, command: ${configEnv.command}`);
const { command, mode } = configEnv;
const isBuild = command === 'build';
const env = loadEnv(mode, process.cwd());
if (process.env.CI) {
for (const [key, value] of Object.entries(env)) {
consola.info(`[vite.config.ts] env: ${key}: ${value}`);
}
}
return {
base: env.VITE_APP_BASE,
build: {
minify: env.VITE_BUILD_MINIFY === 'true' ? undefined /* 即默认 */ : false, // 默认: 'terser'
sourcemap: env.VITE_BUILD_SOURCE_MAP === 'true',
rollupOptions: viteConfigRollupOptions,
},
css: {
devSourcemap: true,
preprocessorOptions: {
scss: {
// 使用 Sass 的现代编译器 API提供更好的性能和新功能支持
api: 'modern-compiler',
additionalData: `@use "@/styles/scss/global.scss" as *;`,
},
},
},
plugins: await loadPlugins(configEnv),
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
define: {
__DEV__: JSON.stringify(!isBuild),
},
server: {
allowedHosts: ['.NWCT.DEV'],
proxy: createViteProxy(),
watch: {
// 监听 vite-plugins 目录的变化,触发配置文件重新加载
ignored: ['!**/vite-plugins/**'],
},
},
optimizeDeps: optimizeDeps(),
};
});