2024-07-24 04:47:02 -05:00
|
|
|
/** @fileoverview The common config for frontend projects. */
|
|
|
|
|
2024-07-24 00:52:44 -05:00
|
|
|
import { Rollup, UserConfig } from 'vite';
|
|
|
|
|
2024-07-24 21:07:28 -05:00
|
|
|
export const manualChunks: Rollup.GetManualChunk = (id, { getModuleInfo }) => {
|
|
|
|
const hasReactDependency = (id: string): boolean => {
|
|
|
|
return getModuleInfo(id)
|
|
|
|
?.importedIds
|
|
|
|
.some((importedId) =>
|
|
|
|
importedId.includes('react') ||
|
|
|
|
importedId.includes('react-dom')
|
|
|
|
) ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Caution: React-related packages should be bundled together otherwise it will cause runtime errors
|
|
|
|
if (id.includes('/node_modules/') && hasReactDependency(id)) {
|
|
|
|
return 'react';
|
|
|
|
}
|
|
|
|
|
2024-07-24 00:52:44 -05:00
|
|
|
if (id.includes('/@logto/')) {
|
2024-07-24 21:07:28 -05:00
|
|
|
return '@logto';
|
2024-07-24 00:52:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (id.includes('/node_modules/')) {
|
|
|
|
return 'vendors';
|
|
|
|
}
|
|
|
|
|
|
|
|
const match = /\/lib\/locales\/([^/]+)/.exec(id);
|
|
|
|
if (match?.[1]) {
|
|
|
|
return `phrases-${match[1]}`;
|
|
|
|
}
|
|
|
|
};
|
2024-07-24 04:47:02 -05:00
|
|
|
|
|
|
|
export const defaultConfig: UserConfig = {
|
|
|
|
resolve: {
|
|
|
|
alias: [
|
|
|
|
{
|
|
|
|
find: /^@\//,
|
|
|
|
replacement: '/src/',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
build: {
|
2024-07-24 00:55:41 -05:00
|
|
|
sourcemap: true,
|
2024-07-24 04:47:02 -05:00
|
|
|
rollupOptions: {
|
2024-07-24 00:52:44 -05:00
|
|
|
output: { manualChunks },
|
2024-07-24 04:47:02 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|