-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Conversation
if ( | ||
bundle[file].type === 'asset' && | ||
!file.includes('ssr-manifest.json') | ||
!file.includes('ssr-manifest.json') && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was also .includes
in the original code, but would this be better as .endsWith
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that does sound like it'd be better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I have updated this as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should align with this
vite/packages/vite/src/node/ssr/ssrManifestPlugin.ts
Lines 79 to 82 in 394148e
fileName: | |
typeof config.build.ssrManifest === 'string' | |
? config.build.ssrManifest | |
: 'ssr-manifest.json', |
instead since the manifest file name can be changed. It's a separate bug though so it can be handled separately if it's a lot of work.
9592328
to
2944fd8
Compare
Rollup 3 switched the way sourcemaps were handled to be more consistent between the in-memory representation and what ultimately gets emitted to disk. Part of this change was moving the sourcemaps themselves to be assets within the bundle. At the same time, vite's `generateBundle` hook for the `assetPlugin` is configured to delete assets within the bundle (with the exception of "ssr-manifest.json"). Since `.js.map` files are now considered assets within the bundle at this stage, vite is removing the sourcemaps from the bundle when `build.ssr = true` and they never wind up on disk. This change adds an additional check to see if the file ends with `.js.map`, `.cjs.map`, or `.mjs.map` and it will leave these files in the bundle so that they are emitted to the outDir when the bundle is written.
2944fd8
to
d1911d6
Compare
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
91ac43b
to
4349592
Compare
I think perhaps we should hold off on this PR and merge #11430 instead, which would also fix this issue as well as others |
#11430 introduces a more controversial change which needs to be discussed in a meeting first. I think we should fix this soon as a patch when it's ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. sounds fine to me
Fix: #11344
Description
Rollup 3 switched the way sourcemaps were handled to be more consistent between the in-memory representation and what ultimately gets emitted to disk. Part of this change was moving the sourcemaps themselves to be assets within the bundle.
At the same time, vite's
generateBundle
hook for theassetPlugin
is configured to delete assets within the bundle (with the exception of "ssr-manifest.json"). Since.js.map
files are now considered assets within the bundle at this stage, vite is removing the sourcemaps from the bundle whenbuild.ssr = true
and they never wind up on disk.This change adds an additional check to see if the file ends with
.js.map
,.cjs.map
, or.mjs.map
and it will leave these files in the bundle so that they are emitted to the outDir when the bundle is written.Additional context
Relevant rollup change that introduced this regression: rollup/rollup#4605
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).