vite icon indicating copy to clipboard operation
vite copied to clipboard

Prebundle handle dynamic import vars

Open ruiming opened this issue 4 years ago • 3 comments

Description

When pre bundle dependencies with ESBuild. ESBuild cannot handle dynamic import properly.

image

A warning appears when start up

image

Suggested solution

Provide an option to allow pre bundle dependencies using rollup

related issue: #8781

Alternative

No response

Additional context

No response

Validations

ruiming avatar Aug 15 '22 15:08 ruiming

See https://esbuild.github.io/api/#non-analyzable-imports, esbuild only works with statically-defined imports.

Can you import a specific locale18 module, such as import('./locales/locale18.js') instead of using a concat expression.

sun0day avatar Aug 16 '22 04:08 sun0day

Using Rollup to prebundle isn't quite a flip of a switch we can do. From what I can tell, Vite could provide an esbuild plugin like https://github.com/RtVision/esbuild-dynamic-import to handle dynamic import vars in esbuild.

bluwy avatar Aug 16 '22 15:08 bluwy

Revisiting this, dynamic import vars in library code is non-standard, and I don't think we should support that. If you need libraries handled by Vite directly, you can add it to optimizeDeps.exclude. Or use the linked esbuild plugin.

bluwy avatar Apr 01 '23 14:04 bluwy