diff --git a/playground/ssr-deps/__tests__/ssr-deps.spec.ts b/playground/ssr-deps/__tests__/ssr-deps.spec.ts index b61cb355f..0d09facb9 100644 --- a/playground/ssr-deps/__tests__/ssr-deps.spec.ts +++ b/playground/ssr-deps/__tests__/ssr-deps.spec.ts @@ -119,6 +119,13 @@ test('import css library', async () => { expect(await page.textContent('.module-condition')).toMatch('[success]') }) +test('optimize-deps-nested-include', async () => { + await page.goto(url) + expect(await page.textContent('.optimize-deps-nested-include')).toMatch( + 'nested-include', + ) +}) + describe.runIf(isServe)('hmr', () => { // TODO: the server file is not imported on the client at all // so it's not present in the client moduleGraph anymore diff --git a/playground/ssr-deps/nested-exclude/index.js b/playground/ssr-deps/nested-exclude/index.js new file mode 100644 index 000000000..c3dc5c01b --- /dev/null +++ b/playground/ssr-deps/nested-exclude/index.js @@ -0,0 +1,3 @@ +export { default as nestedInclude } from '@vitejs/test-nested-include' + +export default 'nested-exclude' diff --git a/playground/ssr-deps/nested-exclude/package.json b/playground/ssr-deps/nested-exclude/package.json new file mode 100644 index 000000000..3e12e0111 --- /dev/null +++ b/playground/ssr-deps/nested-exclude/package.json @@ -0,0 +1,10 @@ +{ + "name": "@vitejs/test-nested-exclude", + "private": true, + "version": "1.0.0", + "type": "module", + "main": "index.js", + "dependencies": { + "@vitejs/test-nested-include": "file:../nested-include" + } +} diff --git a/playground/ssr-deps/nested-include/index.js b/playground/ssr-deps/nested-include/index.js new file mode 100644 index 000000000..547417fcf --- /dev/null +++ b/playground/ssr-deps/nested-include/index.js @@ -0,0 +1,2 @@ +// written in cjs, optimization should convert this to esm +module.exports = 'nested-include' diff --git a/playground/ssr-deps/nested-include/package.json b/playground/ssr-deps/nested-include/package.json new file mode 100644 index 000000000..d4b97a206 --- /dev/null +++ b/playground/ssr-deps/nested-include/package.json @@ -0,0 +1,6 @@ +{ + "name": "@vitejs/test-nested-include", + "private": true, + "version": "1.0.0", + "main": "index.js" +} diff --git a/playground/ssr-deps/package.json b/playground/ssr-deps/package.json index 17c0c94d2..9ed18a607 100644 --- a/playground/ssr-deps/package.json +++ b/playground/ssr-deps/package.json @@ -26,6 +26,7 @@ "@vitejs/test-non-optimized-with-nested-external": "workspace:*", "@vitejs/test-optimized-with-nested-external": "file:./optimized-with-nested-external", "@vitejs/test-optimized-cjs-with-nested-external": "file:./optimized-with-nested-external", + "@vitejs/test-nested-exclude": "file:./nested-exclude", "@vitejs/test-external-using-external-entry": "file:./external-using-external-entry", "@vitejs/test-external-entry": "file:./external-entry", "@vitejs/test-linked-no-external": "link:./linked-no-external", diff --git a/playground/ssr-deps/server.js b/playground/ssr-deps/server.js index 52134ea16..ebdc5be4a 100644 --- a/playground/ssr-deps/server.js +++ b/playground/ssr-deps/server.js @@ -42,13 +42,20 @@ export async function createServer(root = process.cwd(), hmrPort) { }, appType: 'custom', ssr: { - noExternal, + noExternal: [ + ...noExternal, + '@vitejs/test-nested-exclude', + '@vitejs/test-nested-include', + ], external: [ '@vitejs/test-nested-external', '@vitejs/test-external-entry/entry', ], optimizeDeps: { - include: noExternal, + include: [ + ...noExternal, + '@vitejs/test-nested-exclude > @vitejs/test-nested-include', + ], }, }, plugins: [ diff --git a/playground/ssr-deps/src/app.js b/playground/ssr-deps/src/app.js index 719c6eec7..1f1e0c7bb 100644 --- a/playground/ssr-deps/src/app.js +++ b/playground/ssr-deps/src/app.js @@ -23,6 +23,7 @@ import '@vitejs/test-non-optimized-with-nested-external' import * as optimizedWithNestedExternal from '@vitejs/test-optimized-with-nested-external' import * as optimizedCjsWithNestedExternal from '@vitejs/test-optimized-cjs-with-nested-external' +import * as optimizeDepsNestedInclude from '@vitejs/test-nested-exclude' import { setMessage } from '@vitejs/test-external-entry/entry' setMessage('Hello World!') @@ -94,5 +95,7 @@ export async function render(url, rootDir) { html += `\n

` + html += `\n

message from optimize-deps-nested-include: ${optimizeDepsNestedInclude.nestedInclude}

` + return html + '\n' } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 746fa2bef..cee4e12db 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1372,6 +1372,9 @@ importers: '@vitejs/test-module-condition': specifier: file:./module-condition version: file:playground/ssr-deps/module-condition + '@vitejs/test-nested-exclude': + specifier: file:./nested-exclude + version: file:playground/ssr-deps/nested-exclude '@vitejs/test-no-external-cjs': specifier: file:./no-external-cjs version: file:playground/ssr-deps/no-external-cjs @@ -1442,10 +1445,18 @@ importers: playground/ssr-deps/module-condition: {} + playground/ssr-deps/nested-exclude: + dependencies: + '@vitejs/test-nested-include': + specifier: file:../nested-include + version: file:playground/ssr-deps/nested-include + playground/ssr-deps/nested-external: {} playground/ssr-deps/nested-external-cjs: {} + playground/ssr-deps/nested-include: {} + playground/ssr-deps/no-external-cjs: {} playground/ssr-deps/no-external-css: {} @@ -3357,12 +3368,18 @@ packages: '@vitejs/test-nested-exclude@file:playground/optimize-deps/nested-exclude': resolution: {directory: playground/optimize-deps/nested-exclude, type: directory} + '@vitejs/test-nested-exclude@file:playground/ssr-deps/nested-exclude': + resolution: {directory: playground/ssr-deps/nested-exclude, type: directory} + '@vitejs/test-nested-external@file:playground/ssr-deps/nested-external': resolution: {directory: playground/ssr-deps/nested-external, type: directory} '@vitejs/test-nested-include@file:playground/optimize-deps/nested-include': resolution: {directory: playground/optimize-deps/nested-include, type: directory} + '@vitejs/test-nested-include@file:playground/ssr-deps/nested-include': + resolution: {directory: playground/ssr-deps/nested-include, type: directory} + '@vitejs/test-no-external-cjs@file:playground/ssr-deps/no-external-cjs': resolution: {directory: playground/ssr-deps/no-external-cjs, type: directory} @@ -8803,10 +8820,16 @@ snapshots: dependencies: '@vitejs/test-nested-include': file:playground/optimize-deps/nested-include + '@vitejs/test-nested-exclude@file:playground/ssr-deps/nested-exclude': + dependencies: + '@vitejs/test-nested-include': file:playground/ssr-deps/nested-include + '@vitejs/test-nested-external@file:playground/ssr-deps/nested-external': {} '@vitejs/test-nested-include@file:playground/optimize-deps/nested-include': {} + '@vitejs/test-nested-include@file:playground/ssr-deps/nested-include': {} + '@vitejs/test-no-external-cjs@file:playground/ssr-deps/no-external-cjs': {} '@vitejs/test-no-external-css@file:playground/ssr-deps/no-external-css': {}