Skip to content

Commit 2f6a489

Browse files
don't import all modes configs, just the required one
1 parent 6222028 commit 2f6a489

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const mode = import.meta.env.MODE
55
const site_id = import.meta.env.VITE_SITE_ID
66

77
// Use Vite's import.meta.glob to conditionally load mode-specific configs
8+
// This will actually only include the specific config file of the current mode
9+
// thanks to vite.config.mts dynamicImport plugin
810
const modeConfigs = import.meta.glob('@siteConfig/config.*.yaml', {
911
eager: true
1012
})

vite.config.mts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ export default defineConfig(({ mode }) => {
9090
routeFile.includes(`custom/${env.VITE_SITE_ID}/routes.ts`)
9191
)
9292
}
93+
// Include only the current mode's config file in the bundle
94+
// to prevent /src/config.ts from including all config files before picking the right one
95+
if (id.includes('/src/config.ts')) {
96+
return files.filter((configFile) =>
97+
configFile.includes(
98+
`configs/${env.VITE_SITE_ID}/config.${mode}.yaml`
99+
)
100+
)
101+
}
93102
}
94103
})
95104
],

0 commit comments

Comments
 (0)