mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-08-04 22:40:11 +00:00
build: optimize Rolldown chunk splitting
This commit is contained in:
+20
-59
@@ -258,39 +258,12 @@ function searchIndexPolicyPlugin(isDemo: boolean): Plugin {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function resourcePriorityPlugin(isDemo: boolean): Plugin {
|
|
||||||
return {
|
|
||||||
name: 'nodewarden-resource-priority',
|
|
||||||
enforce: 'post' as const,
|
|
||||||
transformIndexHtml(html: string) {
|
|
||||||
if (isDemo || !html.includes('/assets/app-suite-')) return html;
|
|
||||||
|
|
||||||
const scriptMatch = html.match(/^\s*<script type="module" crossorigin src="\/assets\/index-[^"]+\.js"><\/script>\s*$/m);
|
|
||||||
const appSuiteMatch = html.match(/^\s*<link rel="modulepreload" crossorigin href="\/assets\/app-suite-[^"]+\.js">\s*$/m);
|
|
||||||
const stylesheetMatch = html.match(/^\s*<link rel="stylesheet" crossorigin href="\/assets\/index-[^"]+\.css">\s*$/m);
|
|
||||||
|
|
||||||
if (!scriptMatch || !appSuiteMatch || !stylesheetMatch) return html;
|
|
||||||
|
|
||||||
const prioritizedTags = [
|
|
||||||
stylesheetMatch[0].replace('rel="stylesheet"', 'rel="stylesheet" fetchpriority="high"'),
|
|
||||||
appSuiteMatch[0].replace('rel="modulepreload"', 'rel="modulepreload" fetchpriority="high"'),
|
|
||||||
scriptMatch[0].replace('type="module"', 'type="module" fetchpriority="high"'),
|
|
||||||
].join('\n');
|
|
||||||
|
|
||||||
return html
|
|
||||||
.replace(scriptMatch[0], '')
|
|
||||||
.replace(appSuiteMatch[0], '')
|
|
||||||
.replace(stylesheetMatch[0], prioritizedTags);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export default defineConfig(({ mode }) => {
|
export default defineConfig(({ mode }) => {
|
||||||
const isDemo = mode === 'demo';
|
const isDemo = mode === 'demo';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
root: rootDir,
|
root: rootDir,
|
||||||
plugins: [preact(), searchIndexPolicyPlugin(isDemo), resourcePriorityPlugin(isDemo), pwaServiceWorkerPlugin(isDemo)],
|
plugins: [preact(), searchIndexPolicyPlugin(isDemo), pwaServiceWorkerPlugin(isDemo)],
|
||||||
define: {
|
define: {
|
||||||
__NODEWARDEN_DEMO__: JSON.stringify(isDemo),
|
__NODEWARDEN_DEMO__: JSON.stringify(isDemo),
|
||||||
},
|
},
|
||||||
@@ -311,41 +284,29 @@ export default defineConfig(({ mode }) => {
|
|||||||
sourcemap: false,
|
sourcemap: false,
|
||||||
target: 'esnext',
|
target: 'esnext',
|
||||||
chunkSizeWarningLimit: 800,
|
chunkSizeWarningLimit: 800,
|
||||||
rollupOptions: {
|
rolldownOptions: {
|
||||||
treeshake: {
|
checks: {
|
||||||
preset: 'smallest',
|
pluginTimings: false,
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
manualChunks(id) {
|
codeSplitting: {
|
||||||
|
groups: [
|
||||||
|
{
|
||||||
|
name: 'shared',
|
||||||
|
minShareCount: 2,
|
||||||
|
minSize: 50 * 1024,
|
||||||
|
priority: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name(id) {
|
||||||
const normalized = id.replace(/\\/g, '/');
|
const normalized = id.replace(/\\/g, '/');
|
||||||
|
|
||||||
const localeMatch = normalized.match(/\/src\/lib\/i18n\/locales\/(.+)\.ts$/);
|
const localeMatch = normalized.match(/\/src\/lib\/i18n\/locales\/(.+)\.ts$/);
|
||||||
if (localeMatch) {
|
return localeMatch && localeMatch[1] !== 'en' ? `i18n-${localeMatch[1]}` : null;
|
||||||
if (localeMatch[1] === 'en') return undefined;
|
},
|
||||||
return `i18n-${localeMatch[1]}`;
|
test: /[\\/]src[\\/]lib[\\/]i18n[\\/]locales[\\/]/,
|
||||||
}
|
priority: 20,
|
||||||
|
},
|
||||||
if (
|
],
|
||||||
!isDemo &&
|
|
||||||
(
|
|
||||||
normalized.includes('/src/components/VaultPage.tsx') ||
|
|
||||||
normalized.includes('/src/components/ImportPage.tsx') ||
|
|
||||||
normalized.includes('/src/lib/import-') ||
|
|
||||||
normalized.includes('/src/lib/export-formats.ts') ||
|
|
||||||
normalized.includes('/src/components/SendsPage.tsx') ||
|
|
||||||
normalized.includes('/src/components/TotpCodesPage.tsx') ||
|
|
||||||
normalized.includes('/src/components/DomainRulesPage.tsx') ||
|
|
||||||
normalized.includes('/src/components/BackupCenterPage.tsx') ||
|
|
||||||
normalized.includes('/src/components/backup-center/') ||
|
|
||||||
normalized.includes('/src/components/SettingsPage.tsx') ||
|
|
||||||
normalized.includes('/src/components/SecurityDevicesPage.tsx') ||
|
|
||||||
normalized.includes('/src/components/AdminPage.tsx')
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return 'app-suite';
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user