Skip to content

Conversation

nicklozon
Copy link

Description

Sprockets gem appends semicolons to each js asset which corrupts //# sourceMappingURL= magic comments. sprockets-rails fixes this by appending \n//!\n to the asset so the sourceMappingURL is not the last line and in turn not corrupted by the semicolon. This only applies to external sourcemap files.

This PR improves SourcemappingUrlProcessor to also add \n//!\n after sourceMappingURL comments when they contain inline sourcemaps.

class SourcemappingUrlProcessor
REGEX = /\/\/# sourceMappingURL=(.*\.map)/
FILE_REGEX = /\/\/# sourceMappingURL=(.*\.map)/
INLINE_REGEX = /\/\/# sourceMappingURL=(data:.*)$/
Copy link
Author

@nicklozon nicklozon Feb 21, 2024

Choose a reason for hiding this comment

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

Typically inline sourcemaps will look something like this: sourceMappingURL=data:application/json;base64,abc123= where abc123= is encoded data. The regex assumes anything starting with data: is an inline sourcemap, which I fell is a safe assumption from my experience.

@nicklozon nicklozon changed the title Handline Inline Sourcemaps Handle Inline Sourcemaps Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant