2023-08-09 16:55:53 +03:00
|
|
|
import react from '@vitejs/plugin-react';
|
2023-08-29 00:34:56 +03:00
|
|
|
import { defineConfig, loadEnv } from 'vite';
|
2023-07-26 23:11:00 +03:00
|
|
|
|
2023-12-07 23:08:49 +03:00
|
|
|
import { dependencies } from './package.json';
|
2023-08-13 23:51:48 +03:00
|
|
|
|
2023-12-07 23:08:49 +03:00
|
|
|
const inlinePackages = ['react', 'react-router-dom', 'react-dom'];
|
2023-08-13 23:51:48 +03:00
|
|
|
function renderChunks(deps: Record<string, string>) {
|
2023-12-07 23:08:49 +03:00
|
|
|
const chunks = {};
|
2023-08-13 23:51:48 +03:00
|
|
|
Object.keys(deps).forEach((key) => {
|
2023-12-07 23:08:49 +03:00
|
|
|
if (inlinePackages.includes(key)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
chunks[key] = [key];
|
2023-08-13 23:51:48 +03:00
|
|
|
})
|
2023-12-07 23:08:49 +03:00
|
|
|
return chunks;
|
2023-08-13 23:51:48 +03:00
|
|
|
}
|
|
|
|
|
2023-07-26 23:11:00 +03:00
|
|
|
// https://vitejs.dev/config/
|
2023-08-29 00:34:56 +03:00
|
|
|
export default (({ mode }: { mode: string }) => {
|
2023-12-07 23:08:49 +03:00
|
|
|
process.env = {
|
|
|
|
...process.env,
|
|
|
|
...loadEnv(mode, process.cwd())
|
|
|
|
};
|
2023-08-29 00:34:56 +03:00
|
|
|
const enableHttps = process.env.VITE_PORTAL_FRONT_HTTPS === 'true';
|
|
|
|
return defineConfig({
|
|
|
|
plugins: [react()],
|
|
|
|
server: {
|
|
|
|
port: Number(process.env.VITE_PORTAL_FRONT_PORT),
|
|
|
|
|
|
|
|
// NOTE: https is not used for dev builds currently
|
|
|
|
https: enableHttps,
|
|
|
|
},
|
|
|
|
build: {
|
|
|
|
chunkSizeWarningLimit: 4000, // KB
|
|
|
|
sourcemap: false,
|
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
|
|
|
manualChunks: {
|
|
|
|
// Load chunks for dependencies separately
|
|
|
|
...renderChunks(dependencies),
|
|
|
|
},
|
2023-08-13 23:51:48 +03:00
|
|
|
},
|
|
|
|
},
|
2023-08-29 00:34:56 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|