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

Handline Inline Sourcemaps #522

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

@@ -2,21 +2,25 @@ module Sprockets
module Rails
# Rewrites source mapping urls with the digested paths and protect against semicolon appending with a dummy comment line
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.

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