fix: sourcemap generation for story files #11
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related Counter PR at Storybook: storybookjs/storybook#27171
Currently, the sourcemap generation for story files is broken. If rspack behaves like Webpack, then loaders have to chain sourcemaps. This doesn't happen automatically, as Vite/Rollup does. The issue is that the magic-string doesn't support sourcemap chaining currently.
The files I have touched only add content at the end of the file. Therefore, creating source maps is not essential since the line/column mapping will stay the same.
This fix only ensures that the source view with enabled sourcemaps in the browser isn't completely broken for
.stories.ts|js
files. The source map mapping still doesn't refer to the original file, but some compiled file returned by some loader in between. I haven't spent too much time to figure out the issue altogether. Someone else could continue from here. The linked PR in Storybook fixes source maps completely for Vite and Webpack5 builders in StorybookReproduction