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 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'),