fix(lib): remove pure CSS dynamic import (#17601) · vitejs/vite@055f1c1 (original) (raw)

File tree

Original file line number Diff line number Diff line change
@@ -403,7 +403,9 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
403 403 return
404 404 }
405 405
406 -if (ssr |
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) {
407 409 const removedPureCssFiles = removedPureCssFilesCache.get(config)
408 410 if (removedPureCssFiles && removedPureCssFiles.size > 0) {
409 411 for (const file in bundle) {
Original file line number Diff line number Diff line change
@@ -67,6 +67,14 @@ describe.runIf(isBuild)('build', () => {
67 67 expect(code).toMatch(/await import\("\.\/message-[-\w]{8}.js"\)/)
68 68 })
69 69
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 +
70 78 test('@import hoist', async () => {
71 79 serverLogs.forEach((log) => {
72 80 // no warning from esbuild css minifier