From 2ff5930e02d80d6254037281b4c62b8e489d63ba Mon Sep 17 00:00:00 2001 From: sun0day Date: Wed, 1 Feb 2023 01:19:52 +0800 Subject: [PATCH] fix(plugin-legacy): legacy sourcemap not generate (fix #11693) (#11841) --- packages/plugin-legacy/src/index.ts | 2 +- playground/legacy/__tests__/legacy.spec.ts | 11 +++++++++++ playground/legacy/vite.config.js | 1 + 3 files changed, 13 insertions(+), 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] } } diff --git a/playground/legacy/__tests__/legacy.spec.ts b/playground/legacy/__tests__/legacy.spec.ts index 77d317a55250f0..86f537a57ebf7e 100644 --- a/playground/legacy/__tests__/legacy.spec.ts +++ b/playground/legacy/__tests__/legacy.spec.ts @@ -120,4 +120,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'),