ConceptPortal-public/rsconcept/frontend/vite.config.ts

53 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-08-09 16:55:53 +03:00
import react from '@vitejs/plugin-react';
import path from 'path';
import { defineConfig, loadEnv } from 'vite';
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
}
// https://vitejs.dev/config/
export default (({ mode }: { mode: string }) => {
2023-12-07 23:08:49 +03:00
process.env = {
...process.env,
...loadEnv(mode, process.cwd())
};
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
},
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
}
}
});
});