52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
|
import { resolve } from 'node:path';
|
||
|
import { fileURLToPath, URL } from 'node:url';
|
||
|
import postcssPresetEnv from 'postcss-preset-env';
|
||
|
import { defineConfig, loadEnv } from 'vite';
|
||
|
import type { Env } from '@handpear/zod';
|
||
|
import { loadPlugins } from './plugins';
|
||
|
import { resolveEnv, resolveProxy } from './plugins/resolve';
|
||
|
|
||
|
declare global {
|
||
|
interface ImportMetaEnv extends Zod.infer<typeof Env> {}
|
||
|
}
|
||
|
|
||
|
export default defineConfig((config) => {
|
||
|
const isProd = config.mode === 'production';
|
||
|
const envDir = resolve(process.cwd(), '../../');
|
||
|
const ENV = resolveEnv(loadEnv(config.mode, envDir));
|
||
|
|
||
|
return {
|
||
|
base: ENV.VITE_PUBLIC_PATH[2]!,
|
||
|
envDir,
|
||
|
resolve: {
|
||
|
alias: { '~': fileURLToPath(new URL('./src', import.meta.url)) },
|
||
|
},
|
||
|
server: {
|
||
|
host: true,
|
||
|
proxy: resolveProxy(ENV.VITE_PROXY),
|
||
|
},
|
||
|
build: {
|
||
|
reportCompressedSize: false,
|
||
|
minify: 'terser',
|
||
|
terserOptions: {
|
||
|
compress: {
|
||
|
drop_console: isProd,
|
||
|
drop_debugger: isProd,
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
css: {
|
||
|
devSourcemap: true,
|
||
|
postcss: {
|
||
|
plugins: [
|
||
|
postcssPresetEnv({
|
||
|
autoprefixer: {},
|
||
|
features: { 'nesting-rules': true },
|
||
|
}),
|
||
|
],
|
||
|
},
|
||
|
},
|
||
|
plugins: loadPlugins(ENV, isProd),
|
||
|
};
|
||
|
});
|