I use Vite api builder
and with a custom plugin I replace some variables in the code, let's say I have const __CONFIG__ = {};
it's being replaced with a real object during the build.
So for the compiler it will be just a plain object and based on it I want to include some components into my bundle.
I created a simplified example with 2 dynamic imports: one of them never executes. Despite of it, all 2 modules being included in the output bundle.
I tried different ways, for example this one includes all imports:
const getBasic = () => import('./BasicTemplate.svelte')
const getAdv = () => import('./AdvancedTemplate.svelte')
const imports = {
'basic': getBasic,
'advanced': getAdv,
}
const builder = async () => {
const Component = (await imports['advanced']()).default
new Component({
target: document.getElementById('app'),
})
}
builder()
But this includes only 1 import:
const builder = async () => {
if (false) {
const Component = (await import('./BasicTemplate.svelte')).default
new Component({
target: document.getElementById('app'),
})
}
const Component = (await import('./AdvancedTemplate.svelte')).default
new Component({
target: document.getElementById('app'),
})
}
builder()
Is there any way to include only those modules which actually executed?