Opened 3 years ago

Closed 3 years ago

#32383 closed New feature (fixed)

ManifestStaticFilesStorage doesn't update JavaScript source map references

Reported by: Adam Johnson Owned by: Adam Johnson
Component: contrib.staticfiles Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Adam Johnson)

ManifestStaticFilesStorage replaces URL's in CSS files with the hashed equivalents, but doesn't have any other out-of-the-box rules. One common use case for cross-static-file-references is a JavaScript source map, a structured comment in a JS file.

I think it would be a reasonable inclusion that Django modifies these too. I got it working (with Whitenoise's subclass of ManifestStaticFilesStorage) with this extra regex pattern:

from whitenoise.storage import CompressedManifestStaticFilesStorage


class SuperStaticFilesStorage(CompressedManifestStaticFilesStorage):
    patterns = CompressedManifestStaticFilesStorage.patterns + (
        (
            "*.js",
            (
                (
                    r"(//# sourceMappingURL=(.*?\.js\.map))$",
                    "//# sourceMappingURL=%s",
                ),
            ),
        ),
    )

Ideally the regex would start with a ^, which requires the regex mulitline flag, and would NOT be compiled in case-insenstive mode. The current storage implementation forces compiling regexes with only the case insensitive flag.

Change History (7)

comment:1 Changed 3 years ago by Kiran Baby

Owner: changed from nobody to Kiran Baby
Status: newassigned

comment:2 Changed 3 years ago by Kiran Baby

Owner: Kiran Baby deleted
Status: assignednew

comment:3 Changed 3 years ago by Carlton Gibson

Triage Stage: UnreviewedAccepted

Yep. If we can do this then super 👍

comment:4 Changed 3 years ago by Adam Johnson

Description: modified (diff)
Owner: set to Adam Johnson
Status: newassigned

comment:5 Changed 3 years ago by Adam Johnson

Has patch: set
Last edited 3 years ago by Mariusz Felisiak (previous) (diff)

comment:6 Changed 3 years ago by Mariusz Felisiak

Triage Stage: AcceptedReady for checkin

comment:7 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In e32722d1:

Fixed #32383 -- Added source map support to ManifestStaticFilesStorage.

Note: See TracTickets for help on using tickets.
Back to Top