Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ssr): emit js sourcemaps for ssr builds #11343

Merged
merged 2 commits into from Dec 31, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/vite/src/node/plugins/asset.ts
Expand Up @@ -23,6 +23,7 @@ export const assetUrlRE = /__VITE_ASSET__([a-z\d]+)__(?:\$_(.*?)__)?/g

const rawRE = /(?:\?|&)raw(?:&|$)/
const urlRE = /(\?|&)url(?:&|$)/
const jsSourceMapRE = /\.[cm]?js\.map$/

const assetCache = new WeakMap<ResolvedConfig, Map<string, string>>()

Expand Down Expand Up @@ -187,10 +188,13 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
generateBundle(_, bundle) {
// do not emit assets for SSR build
if (config.command === 'build' && config.build.ssr) {
for (const file in bundle) {
const assetFiles = Object.keys(bundle).filter(
(file) => bundle[file].type === 'asset',
)
for (const file of assetFiles) {
if (
bundle[file].type === 'asset' &&
!file.includes('ssr-manifest.json')
!file.endsWith('ssr-manifest.json') &&
!jsSourceMapRE.test(file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid the Object.keys and filter here as they create new objects that takes up memory. We could stick with the for in loop like before and add the sourcemap check for a tiny bit of perf.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make that change, I've been OOO on vacation the past few weeks

) {
delete bundle[file]
}
Expand Down