sbt-idp/cope2n-fe/vite.config.ts

66 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-11-30 11:19:06 +00:00
import react from '@vitejs/plugin-react';
// import { visualizer } from 'rollup-plugin-visualizer';
import { CommonServerOptions, defineConfig, loadEnv, ProxyOptions } from 'vite';
2024-01-31 04:08:20 +00:00
import svgrPlugin from 'vite-plugin-svgr';
2023-11-30 11:19:06 +00:00
import viteTsconfigPaths from 'vite-tsconfig-paths';
2024-01-31 04:08:20 +00:00
const DEFAULT_PORT = 8080;
2023-11-30 11:19:06 +00:00
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,
2024-01-31 04:08:20 +00:00
// followRedirects: true,
2023-11-30 11:19:06 +00:00
};
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(),
2024-01-31 04:08:20 +00:00
svgrPlugin(),
2023-11-30 11:19:06 +00:00
],
server: {
open: true,
port: configPort(env),
proxy: configProxy(env),
},
2023-11-30 11:19:06 +00:00
define: {
'process.env': env,
},
build: {
minify: true,
chunkSizeWarningLimit: 1024, // 1MB
// Uncomment rollup `visualizer` plugin to generate bundle size analyzer
// rollupOptions: {
// plugins: [visualizer()],
// },
},
};
});