Skip to content

Commit

Permalink
fix(plugin-legacy): legacy sourcemap not generate (fix vitejs#11693) (v…
Browse files Browse the repository at this point in the history
  • Loading branch information
sun0day authored and futurGH committed Feb 26, 2023
1 parent a097a83 commit 1d1603c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
Expand Down
11 changes: 11 additions & 0 deletions playground/legacy/__tests__/legacy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
1 change: 1 addition & 0 deletions playground/legacy/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
build: {
cssCodeSplit: false,
manifest: true,
sourcemap: true,
rollupOptions: {
input: {
index: path.resolve(__dirname, 'index.html'),
Expand Down

0 comments on commit 1d1603c

Please sign in to comment.