2024-07-24 00:52:44 -05:00
|
|
|
import react from '@vitejs/plugin-react';
|
|
|
|
import browserslistToEsbuild from 'browserslist-to-esbuild';
|
|
|
|
import { defineConfig, mergeConfig, type UserConfig } from 'vite';
|
|
|
|
import viteCompression from 'vite-plugin-compression';
|
|
|
|
import svgr from 'vite-plugin-svgr';
|
|
|
|
|
|
|
|
import { defaultConfig, manualChunks } from '../../vite.shared.config';
|
|
|
|
|
|
|
|
const buildConfig = (mode: string): UserConfig => ({
|
|
|
|
server: {
|
|
|
|
port: 5001,
|
|
|
|
hmr: {
|
|
|
|
port: 6001,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
css: {
|
|
|
|
modules: {
|
|
|
|
generateScopedName:
|
|
|
|
// Keep backward compatibility with the old CSS modules naming in production
|
|
|
|
mode === 'development' ? '__[hash:base64:5]__[local]' : '[hash:base64:5]_[local]',
|
|
|
|
},
|
|
|
|
},
|
2024-08-06 09:08:36 -05:00
|
|
|
plugins: [
|
|
|
|
react(),
|
|
|
|
svgr(),
|
|
|
|
viteCompression({ disable: mode === 'development' }),
|
|
|
|
viteCompression({ disable: mode === 'development', algorithm: 'brotliCompress' }),
|
|
|
|
],
|
2024-08-19 04:46:17 -05:00
|
|
|
define: {
|
|
|
|
'import.meta.env.DEV_FEATURES_ENABLED': JSON.stringify(process.env.DEV_FEATURES_ENABLED),
|
|
|
|
},
|
2024-07-24 00:52:44 -05:00
|
|
|
build: {
|
|
|
|
// Use the same browserslist configuration as in README.md.
|
|
|
|
// Consider using the esbuild target directly in the future.
|
|
|
|
target: browserslistToEsbuild('> 0.5%, last 2 versions, Firefox ESR, not dead'),
|
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
2024-07-24 21:07:28 -05:00
|
|
|
// Tip: You can use `pnpx vite-bundle-visualizer` to analyze the bundle size
|
2024-07-24 00:52:44 -05:00
|
|
|
manualChunks: (id, meta) => {
|
|
|
|
if (/\/node_modules\/i18next[^/]*\//.test(id)) {
|
|
|
|
return 'i18next';
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const largePackage of ['libphonenumber-js', 'core-js']) {
|
|
|
|
if (id.includes(`/node_modules/${largePackage}/`)) {
|
|
|
|
return largePackage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return manualChunks(id, meta);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default defineConfig(({ mode }) => mergeConfig(defaultConfig, buildConfig(mode)));
|