summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-03-18 14:05:41 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-03-18 14:06:09 +0100
commitf2923306f152ed4e385e0544f8bc615d7d65c797 (patch)
tree399599a3b4df04a515f570738accd4766a5b83bc /django
parenteff2ba3f8d2f172c64b9df08db8d188e11bae855 (diff)
[4.2.x] Fixed #34322 -- Made ES module support to ManifestStaticFilesStorage optional.
Co-authored-by: Author: Claude Paroz <claude@2xlibre.net> Backport of e10c1688f96e3b2d202fe401472b7b25f6105969 from main
Diffstat (limited to 'django')
-rw-r--r--django/contrib/staticfiles/storage.py52
1 files changed, 30 insertions, 22 deletions
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index 445cf6b954..b388abe575 100644
--- a/django/contrib/staticfiles/storage.py
+++ b/django/contrib/staticfiles/storage.py
@@ -47,6 +47,34 @@ class StaticFilesStorage(FileSystemStorage):
class HashedFilesMixin:
default_template = """url("%(url)s")"""
max_post_process_passes = 5
+ support_js_module_import_aggregation = False
+ _js_module_import_aggregation_patterns = (
+ "*.js",
+ (
+ (
+ (
+ r"""(?P<matched>import(?s:(?P<import>[\s\{].*?))"""
+ r"""\s*from\s*['"](?P<url>[\.\/].*?)["']\s*;)"""
+ ),
+ """import%(import)s from "%(url)s";""",
+ ),
+ (
+ (
+ r"""(?P<matched>export(?s:(?P<exports>[\s\{].*?))"""
+ r"""\s*from\s*["'](?P<url>[\.\/].*?)["']\s*;)"""
+ ),
+ """export%(exports)s from "%(url)s";""",
+ ),
+ (
+ r"""(?P<matched>import\s*['"](?P<url>[\.\/].*?)["']\s*;)""",
+ """import"%(url)s";""",
+ ),
+ (
+ r"""(?P<matched>import\(["'](?P<url>.*?)["']\))""",
+ """import("%(url)s")""",
+ ),
+ ),
+ )
patterns = (
(
"*.css",
@@ -72,34 +100,14 @@ class HashedFilesMixin:
r"(?m)(?P<matched>)^(//# (?-i:sourceMappingURL)=(?P<url>.*))$",
"//# sourceMappingURL=%(url)s",
),
- (
- (
- r"""(?P<matched>import(?s:(?P<import>[\s\{].*?))"""
- r"""\s*from\s*['"](?P<url>[\.\/].*?)["']\s*;)"""
- ),
- """import%(import)s from "%(url)s";""",
- ),
- (
- (
- r"""(?P<matched>export(?s:(?P<exports>[\s\{].*?))"""
- r"""\s*from\s*["'](?P<url>[\.\/].*?)["']\s*;)"""
- ),
- """export%(exports)s from "%(url)s";""",
- ),
- (
- r"""(?P<matched>import\s*['"](?P<url>[\.\/].*?)["']\s*;)""",
- """import"%(url)s";""",
- ),
- (
- r"""(?P<matched>import\(["'](?P<url>.*?)["']\))""",
- """import("%(url)s")""",
- ),
),
),
)
keep_intermediate_files = True
def __init__(self, *args, **kwargs):
+ if self.support_js_module_import_aggregation:
+ self.patterns += (self._js_module_import_aggregation_patterns,)
super().__init__(*args, **kwargs)
self._patterns = {}
self.hashed_files = {}