sbt-idp/cope2n-fe/vite.config.ts
2024-01-31 11:08:20 +07:00

66 lines
1.5 KiB
TypeScript

import react from '@vitejs/plugin-react';
// import { visualizer } from 'rollup-plugin-visualizer';
import { CommonServerOptions, defineConfig, loadEnv, ProxyOptions } from 'vite';
import svgrPlugin from 'vite-plugin-svgr';
import viteTsconfigPaths from 'vite-tsconfig-paths';
const DEFAULT_PORT = 8080;
function configPort(env: Record<string, string>): CommonServerOptions['port'] {
const parsedPort = parseInt(env['VITE_PORT']);
return Number.isNaN(parsedPort) ? DEFAULT_PORT : parsedPort;
}
function configProxy(
env: Record<string, string>,
): CommonServerOptions['proxy'] {
const proxyOptions: ProxyOptions = {
target: env['VITE_PROXY'],
changeOrigin: true,
secure: false,
autoRewrite: true,
// followRedirects: true,
};
if (env['VITE_PROXY']) {
return {
'/api': proxyOptions,
'/backend-static': proxyOptions,
};
}
return undefined;
}
export default defineConfig(({ mode = 'development' }) => {
const env = loadEnv(mode, '.', '');
return {
plugins: [
react({
babel: {
babelrc: true,
},
}),
viteTsconfigPaths(),
svgrPlugin(),
],
// server: {
// open: true,
// port: configPort(env),
// proxy: configProxy(env),
// },
define: {
'process.env': env,
},
build: {
minify: true,
chunkSizeWarningLimit: 1024, // 1MB
// Uncomment rollup `visualizer` plugin to generate bundle size analyzer
// rollupOptions: {
// plugins: [visualizer()],
// },
},
};
});