
diff --git a/umap/templates/umap/content.html b/umap/templates/umap/content.html
index 1019bd6b..a9daf056 100644
--- a/umap/templates/umap/content.html
+++ b/umap/templates/umap/content.html
@@ -1,12 +1,10 @@
{% extends "base.html" %}
-{% load umap_tags compress i18n %}
+{% load umap_tags i18n %}
{% block body_class %}
content
{% endblock body_class %}
{% block extra_head %}
- {% compress css %}
- {% umap_css %}
- {% endcompress css %}
+ {% umap_css %}
{% umap_js %}
{% endblock extra_head %}
{% block header %}
diff --git a/umap/templates/umap/css.html b/umap/templates/umap/css.html
index 120ff967..5d91e589 100644
--- a/umap/templates/umap/css.html
+++ b/umap/templates/umap/css.html
@@ -1,28 +1,30 @@
+{% load static %}
+
+ href="{% static 'umap/vendors/leaflet/leaflet.css' %}" />
+ href="{% static 'umap/vendors/markercluster/MarkerCluster.css' %}" />
+ href="{% static 'umap/vendors/markercluster/MarkerCluster.Default.css' %}" />
+ href="{% static 'umap/vendors/editinosm/Leaflet.EditInOSM.css' %}" />
+ href="{% static 'umap/vendors/minimap/Control.MiniMap.css' %}" />
+ href="{% static 'umap/vendors/contextmenu/leaflet.contextmenu.css' %}" />
+ href="{% static 'umap/vendors/toolbar/leaflet.toolbar.css' %}" />
+ href="{% static 'umap/vendors/measurable/Leaflet.Measurable.css' %}" />
+ href="{% static 'umap/vendors/fullscreen/leaflet.fullscreen.css' %}" />
+ href="{% static 'umap/vendors/locatecontrol/L.Control.Locate.css' %}" />
-
-
-
-
-
-
+ href="{% static 'umap/vendors/iconlayers/iconLayers.css' %}" />
+
+
+
+
+
+
diff --git a/umap/templates/umap/js.html b/umap/templates/umap/js.html
index 235f4a51..62df6bab 100644
--- a/umap/templates/umap/js.html
+++ b/umap/templates/umap/js.html
@@ -1,62 +1,53 @@
-{% load compress %}
-{% compress js %}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-{% endcompress %}
-{% if locale %}{% endif %}
-{% compress js %}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-{% endcompress %}
+{% load static %}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{% if locale %}
+ {% with "umap/locale/"|add:locale|add:".js" as path %}
+
+ {% endwith %}
+{% endif %}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/umap/templates/umap/map_detail.html b/umap/templates/umap/map_detail.html
index 25f927e7..42000f4a 100644
--- a/umap/templates/umap/map_detail.html
+++ b/umap/templates/umap/map_detail.html
@@ -1,5 +1,5 @@
{% extends "base.html" %}
-{% load umap_tags compress i18n %}
+{% load umap_tags i18n %}
{% block head_title %}
{{ map.name }} - {{ SITE_NAME }}
{% endblock head_title %}
@@ -7,9 +7,7 @@
map_detail
{% endblock body_class %}
{% block extra_head %}
- {% compress css %}
- {% umap_css %}
- {% endcompress %}
+ {% umap_css %}
{% umap_js locale=locale %}
{% if object.share_status != object.PUBLIC %}
{% endif %}
{% endblock extra_head %}
diff --git a/umap/tests/integration/test_statics.py b/umap/tests/integration/test_statics.py
new file mode 100644
index 00000000..657609b1
--- /dev/null
+++ b/umap/tests/integration/test_statics.py
@@ -0,0 +1,43 @@
+import re
+import shutil
+import tempfile
+
+import pytest
+from django.core.management import call_command
+from django.utils.translation import override
+from playwright.sync_api import expect
+
+
+@pytest.fixture
+def staticfiles(settings):
+ static_root = tempfile.mkdtemp(prefix="test_static")
+ settings.STATIC_ROOT = static_root
+ try:
+ call_command("collectstatic", "--noinput")
+ yield
+ finally:
+ shutil.rmtree(static_root)
+
+
+def test_javascript_have_been_loaded(
+ map, live_server, datalayer, page, settings, staticfiles
+):
+ settings.STORAGES["staticfiles"][
+ "BACKEND"
+ ] = "umap.utils.UmapManifestStaticFilesStorage"
+ datalayer.settings["displayOnLoad"] = False
+ datalayer.save()
+ map.settings["properties"]["defaultView"] = "latest"
+ map.save()
+ with override("fr"):
+ url = f"{live_server.url}{map.get_absolute_url()}"
+ assert "/fr/" in url
+ page.goto(url)
+ # Hash is defined, so map is initialized
+ expect(page).to_have_url(re.compile(r".*#7/48\..+/13\..+"))
+ expect(page).to_have_url(re.compile(r".*/fr/"))
+ # Should be in French, so hashed locale file has been loaded correctly
+ button = page.get_by_text("Voir les calques")
+ expect(button).to_be_visible()
+ layers = page.locator(".umap-browse-datalayers li")
+ expect(layers).to_have_count(1)
diff --git a/umap/tests/settings.py b/umap/tests/settings.py
index 37a72c5f..c79521f0 100644
--- a/umap/tests/settings.py
+++ b/umap/tests/settings.py
@@ -3,9 +3,11 @@ import os
from umap.settings.base import * # pylint: disable=W0614,W0401
SECRET_KEY = "justfortests"
-COMPRESS_ENABLED = False
FROM_EMAIL = "test@test.org"
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
+STORAGES["staticfiles"][
+ "BACKEND"
+] = "django.contrib.staticfiles.storage.StaticFilesStorage"
if os.environ.get("GITHUB_ACTIONS", False) == "true":
DATABASES = {
diff --git a/umap/utils.py b/umap/utils.py
index 2a51fe4e..a18f567d 100644
--- a/umap/utils.py
+++ b/umap/utils.py
@@ -2,6 +2,7 @@ import gzip
import os
from django.conf import settings
+from django.contrib.staticfiles.storage import ManifestStaticFilesStorage
from django.urls import URLPattern, URLResolver, get_resolver
@@ -162,3 +163,53 @@ def merge_features(reference: list, latest: list, incoming: list):
merged.append(item)
return merged
+
+
+class UmapManifestStaticFilesStorage(ManifestStaticFilesStorage):
+ support_js_module_import_aggregation = True
+
+ # We remove `;` at the end of all regexps to match our prettier config.
+ _js_module_import_aggregation_patterns = (
+ "*.js",
+ (
+ (
+ (
+ r"""(?P
import(?s:(?P[\s\{].*?))"""
+ r"""\s*from\s*['"](?P[\.\/].*?)["']\s*)"""
+ ),
+ 'import%(import)s from "%(url)s"\n',
+ ),
+ (
+ (
+ r"""(?Pexport(?s:(?P[\s\{].*?))"""
+ r"""\s*from\s*["'](?P[\.\/].*?)["']\s*)"""
+ ),
+ 'export%(exports)s from "%(url)s"\n',
+ ),
+ (
+ r"""(?Pimport\s*['"](?P[\.\/].*?)["']\s*)""",
+ 'import"%(url)s"\n',
+ ),
+ (
+ r"""(?Pimport\(["'](?P.*?)["']\))""",
+ """import("%(url)s")""",
+ ),
+ ),
+ )
+
+ # https://github.com/django/django/blob/0fcee1676c7f14bb08e2cc662898dee56d9cf207↩
+ # /django/contrib/staticfiles/storage.py#L78C5-L105C6
+ patterns = (
+ (
+ "*.css",
+ (
+ r"""(?Purl\(['"]{0,1}\s*(?P.*?)["']{0,1}\))""",
+ (
+ r"""(?P@import\s*["']\s*(?P.*?)["'])""",
+ """@import url("%(url)s")""",
+ ),
+ # Remove CSS source map rewriting
+ ),
+ ),
+ # Remove JS source map rewriting
+ )