diff --git a/docs/config/index.md b/docs/config/index.md index 428dc74cdf6bc4..5cd1a23774400c 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -713,7 +713,16 @@ createServer() Dependencies to exclude from pre-bundling. :::warning CommonJS - CommonJS dependencies should not be excluded from optimization. If an ESM dependency has a nested CommonJS dependency, it should not be excluded as well. + CommonJS dependencies should not be excluded from optimization. If an ESM dependency is excluded from optimization, but has a nested CommonJS dependency, the CommonJS dependency should be added to `optimizeDeps.include`. Example: + + ```js + export default defineConfig({ + optimizeDeps: { + include: ['esm-dep > cjs-dep'] + } + }) + ``` + ::: ### optimizeDeps.include diff --git a/packages/playground/dynamic-import/css/index.css b/packages/playground/dynamic-import/css/index.css index 9d3790dabe47cf..07b64e1de286d0 100644 --- a/packages/playground/dynamic-import/css/index.css +++ b/packages/playground/dynamic-import/css/index.css @@ -1,2 +1,2 @@ -.css { box-sizing: border-box; } -.view { color: red; } +.css { box-sizing: border-box; } +.view { color: red; } diff --git a/packages/playground/nested-deps/__tests__/nested-deps.spec.ts b/packages/playground/nested-deps/__tests__/nested-deps.spec.ts index 69f80bbcf4c6eb..dac548d0e4193e 100644 --- a/packages/playground/nested-deps/__tests__/nested-deps.spec.ts +++ b/packages/playground/nested-deps/__tests__/nested-deps.spec.ts @@ -5,4 +5,6 @@ test('handle nested package', async () => { const c = await page.textContent('.c') expect(c).toBe('es-C@1.0.0') expect(await page.textContent('.side-c')).toBe(c) + expect(await page.textContent('.d')).toBe('D@1.0.0') + expect(await page.textContent('.nested-d')).toBe('D-nested@1.0.0') }) diff --git a/packages/playground/nested-deps/index.html b/packages/playground/nested-deps/index.html index 86a7268cd169d7..3467c3d9e425af 100644 --- a/packages/playground/nested-deps/index.html +++ b/packages/playground/nested-deps/index.html @@ -13,11 +13,18 @@

direct dependency C

side dependency C


 
+

direct dependency D

+

+
+

nested dependency nested-D (dep of D)

+

+