Skip to content

Commit 2ff5930

Browse files
author
sun0day
authored
fix(plugin-legacy): legacy sourcemap not generate (fix #11693) (#11841)
1 parent 5d55083 commit 2ff5930

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

packages/plugin-legacy/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
578578
if (isLegacyBundle(bundle, opts)) {
579579
// avoid emitting duplicate assets
580580
for (const name in bundle) {
581-
if (bundle[name].type === 'asset') {
581+
if (bundle[name].type === 'asset' && !/.+\.map$/.test(name)) {
582582
delete bundle[name]
583583
}
584584
}

playground/legacy/__tests__/legacy.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,15 @@ describe.runIf(isBuild)('build', () => {
120120
expect(findAssetFile(/polyfills-legacy/)).toMatch('"structuredClone"')
121121
expect(findAssetFile(/polyfills-\w{8}\./)).toMatch('"structuredClone"')
122122
})
123+
124+
test('should generate legacy sourcemap file', async () => {
125+
expect(
126+
listAssets().some((filename) => /index-legacy.+\.map$/.test(filename)),
127+
).toBeTruthy()
128+
expect(
129+
listAssets().some((filename) =>
130+
/polyfills-legacy.+\.map$/.test(filename),
131+
),
132+
).toBeFalsy()
133+
})
123134
})

playground/legacy/vite.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
build: {
1515
cssCodeSplit: false,
1616
manifest: true,
17+
sourcemap: true,
1718
rollupOptions: {
1819
input: {
1920
index: path.resolve(__dirname, 'index.html'),

0 commit comments

Comments
 (0)