Skip to content

Commit

Permalink
attempt to use ManifestStaticStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Oct 20, 2023
1 parent 8a02dfe commit 8f25a55
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .deployment/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ENV DJANGO_MEDIA_ROOT=/web/workdir/media
ENV DJANGO_SECRET_KEY=dummy_secret_key
ENV PYTHONPATH=/web
RUN mkdir -p $DJANGO_STATIC_ROOT
RUN ./testapp/manage.py collectstatic --noinput
RUN DJANGO_DEPLOYED=1 ./testapp/manage.py collectstatic --noinput

# handle permissions
RUN useradd -M -d /web -s /bin/bash django
Expand Down
1 change: 1 addition & 0 deletions .deployment/uwsgi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gid = django
http-socket = :8080
env = HOME=/web
env = DJANGO_SETTINGS_MODULE=testapp.settings
env = DJANGO_DEPLOYED=1
module = testapp.wsgi:application
buffer-size = 32768
static-map = /static=$(DJANGO_STATIC_ROOT)
Expand Down
8 changes: 6 additions & 2 deletions testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

DEBUG = os.getenv('DJANGO_DEBUG', '').lower() in ['true', '1', 'yes']

DEPLOYED = os.getenv('DJANGO_DEPLOYED', '').lower() in ['true', '1', 'yes']

ALLOWED_HOSTS = ['*'] if DEBUG else ['localhost', 'django-formset.fly.dev']
CSRF_TRUSTED_ORIGINS = ['https://django-formset.fly.dev']

Expand Down Expand Up @@ -79,13 +81,15 @@

STATIC_URL = '/static/'

STATIC_ROOT = os.getenv('DJANGO_STATIC_ROOT', BASE_DIR / 'workdir/static')

STORAGES = {
'default': {
'BACKEND': 'django.core.files.storage.FileSystemStorage',
},
'staticfiles': {
'BACKEND': 'django.contrib.staticfiles.storage.StaticFilesStorage' if DEBUG else \
'django.contrib.staticfiles.storage.ManifestStaticFilesStorage',
'BACKEND': 'testapp.storage.NoSourceMapsManifestStaticStorage' if DEPLOYED else \
'django.contrib.staticfiles.storage.StaticFilesStorage',
},
}

Expand Down
21 changes: 21 additions & 0 deletions testapp/storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.contrib.staticfiles.storage import ManifestStaticFilesStorage


class NoSourceMapsManifestStaticStorage(ManifestStaticFilesStorage):
patterns = (
(
"*.css",
(
"(?P<matched>url\\(['\"]{0,1}\\s*(?P<url>.*?)[\"']{0,1}\\))",
(
"(?P<matched>@import\\s*[\"']\\s*(?P<url>.*?)[\"'])",
'@import url("%(url)s")',
),
),
),
(
"*.js",
(
),
),
)

0 comments on commit 8f25a55

Please sign in to comment.