Skip to content

Instantly share code, notes, and snippets.

@hwalinga
Last active April 28, 2020 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hwalinga/3cd4ade4478cfb80a6ee887fc5035cf5 to your computer and use it in GitHub Desktop.
Save hwalinga/3cd4ade4478cfb80a6ee887fc5035cf5 to your computer and use it in GitHub Desktop.
Include replacing of ES6 imports for ManifestStaticiFilesStorage
from django.contrib.staticfiles import storage
class IncludeJavascriptImportsStaticFilesStorage(storage.ManifestStaticFilesStorage):
"""
Include patterns that deal with the javascript import files.
It is important to note that the pattern only matches if the file path
starts with / or ./ or ../
I.e. it only matches if the file path is explicitly absolute or relative.
This is to reduce false positives in comments. (Which has happened.)
"""
patterns = storage.HashedFilesMixin.patterns + (
("*.js", (
(r"""( from ["'](\.{,2}/.*?\.js))""", """ from '%s'"""),
)),)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment