Skip to content

Commit 055f1c1

Browse files
authored
fix(lib): remove pure CSS dynamic import (#17601)
1 parent dafff4a commit 055f1c1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/vite/src/node/plugins/importAnalysisBuild.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,9 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
403403
return
404404
}
405405

406-
if (ssr || isWorker) {
406+
// If preload is not enabled, we parse through each imports and remove any imports to pure CSS chunks
407+
// as they are removed from the bundle
408+
if (!insertPreload) {
407409
const removedPureCssFiles = removedPureCssFilesCache.get(config)
408410
if (removedPureCssFiles && removedPureCssFiles.size > 0) {
409411
for (const file in bundle) {

playground/lib/__tests__/lib.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ describe.runIf(isBuild)('build', () => {
6767
expect(code).toMatch(/await import\("\.\/message-[-\w]{8}.js"\)/)
6868
})
6969

70+
test('Library mode does not have any reference to pure CSS chunks', async () => {
71+
const code = readFile('dist/lib/dynamic-import-message.es.mjs')
72+
73+
// Does not import pure CSS chunks and replaced by `Promise.resolve({})` instead
74+
expect(code).not.toMatch(/await import\("\.\/dynamic-[-\w]{8}.js"\)/)
75+
expect(code).toMatch(/await Promise.resolve\(\{.*\}\)/)
76+
})
77+
7078
test('@import hoist', async () => {
7179
serverLogs.forEach((log) => {
7280
// no warning from esbuild css minifier

0 commit comments

Comments
 (0)