ship-gis/vite.config.ts

84 lines
2.0 KiB
TypeScript
Raw Normal View 히스토리

import { defineConfig, loadEnv, type Plugin } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig(({ mode, command }) => {
const env = loadEnv(mode, process.cwd(), '');
const isLocalDev = mode === 'development';
const isBuild = command === 'build';
const base = env.VITE_BASE_URL || '/';
console.log(`[Vite] Mode: ${mode}, Command: ${command}, Base: ${base}, isLocalDev: ${isLocalDev}`);
const excludePatterns: RegExp[] = isBuild && !isLocalDev
? [
/[/\\]publish[/\\]/,
/[/\\]component[/\\]wrap[/\\]/,
]
: [];
return {
base,
define: {
global: 'globalThis',
},
server: {
host: true,
port: 3000,
proxy: {
'/snp-api': {
target: env.VITE_SNP_API_TARGET || 'http://211.208.115.83:8041',
changeOrigin: true,
secure: false,
},
},
},
plugins: [
react(),
isBuild && !isLocalDev && ({
name: 'exclude-dev-folders',
resolveId(source: string) {
const normalizedSource = source.replace(/\\/g, '/');
for (const pattern of excludePatterns) {
if (pattern.test(normalizedSource)) {
return { id: 'virtual:empty-module', moduleSideEffects: false };
}
}
return null;
},
load(id: string) {
if (id === 'virtual:empty-module') {
return 'export default null;';
}
return null;
},
} satisfies Plugin),
].filter(Boolean),
resolve: {
alias: {
'@': '/src',
},
},
esbuild: isBuild && !isLocalDev
? {
drop: ['console', 'debugger'],
}
: {},
build: {
target: 'es2022',
outDir: 'dist',
cssCodeSplit: true,
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-dom', 'react-router-dom'],
map: ['ol', 'ol-ext'],
state: ['zustand'],
},
},
},
},
};
});