From 11e4eb06d42cb865e607d37009ec5962ddfdd6fa Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 29 Jan 2023 16:39:17 +0800 Subject: [PATCH 1/2] fix(plugin-legacy): legacy sourcemap not generate (fix #11693) --- packages/plugin-legacy/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index 9068935bed118b..308049324c5e1a 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -578,7 +578,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { if (isLegacyBundle(bundle, opts)) { // avoid emitting duplicate assets for (const name in bundle) { - if (bundle[name].type === 'asset') { + if (bundle[name].type === 'asset' && !/.+\.map$/.test(name)) { delete bundle[name] } } From c0caa8ef27e7f74705378c5a42a6bf09e759fd92 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 29 Jan 2023 23:11:20 +0800 Subject: [PATCH 2/2] test(plugin-legacy): add legacy sourcemap generate test case --- playground/legacy/__tests__/legacy.spec.ts | 11 +++++++++++ playground/legacy/vite.config.js | 1 + 2 files changed, 12 insertions(+) diff --git a/playground/legacy/__tests__/legacy.spec.ts b/playground/legacy/__tests__/legacy.spec.ts index 290f6b69ac1cf9..f4fe6cb6287c36 100644 --- a/playground/legacy/__tests__/legacy.spec.ts +++ b/playground/legacy/__tests__/legacy.spec.ts @@ -118,4 +118,15 @@ describe.runIf(isBuild)('build', () => { expect(findAssetFile(/polyfills-legacy/)).toMatch('"structuredClone"') expect(findAssetFile(/polyfills-\w{8}\./)).toMatch('"structuredClone"') }) + + test('should generate legacy sourcemap file', async () => { + expect( + listAssets().some((filename) => /index-legacy.+\.map$/.test(filename)), + ).toBeTruthy() + expect( + listAssets().some((filename) => + /polyfills-legacy.+\.map$/.test(filename), + ), + ).toBeFalsy() + }) }) diff --git a/playground/legacy/vite.config.js b/playground/legacy/vite.config.js index 7adf0f784eeeb2..54de28b31949de 100644 --- a/playground/legacy/vite.config.js +++ b/playground/legacy/vite.config.js @@ -14,6 +14,7 @@ module.exports = { build: { cssCodeSplit: false, manifest: true, + sourcemap: true, rollupOptions: { input: { index: path.resolve(__dirname, 'index.html'),