Skip to content

Commit 252f8df

Browse files
authored
fix bug with whitenoise (#14)
* fix bug with whitenoise * add web_framework variable
1 parent 6f9e610 commit 252f8df

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

webpack_boilerplate/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def load_from_django():
1515
user_config = dict(DEFAULT_CONFIG, **getattr(settings, "WEBPACK_LOADER", {}))
1616

1717
user_config["ignores"] = [re.compile(I) for I in user_config["IGNORE"]]
18+
user_config["web_framework"] = "django"
1819
return user_config
1920

2021

@@ -30,6 +31,7 @@ def load_from_flask():
3031
user_config = dict(DEFAULT_CONFIG, **current_app.config["WEBPACK_LOADER"])
3132

3233
user_config["ignores"] = [re.compile(I) for I in user_config["IGNORE"]]
34+
user_config["web_framework"] = "flask"
3335
return user_config
3436

3537

webpack_boilerplate/loader.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,23 @@ def filter_chunks(self, chunks):
4646
yield chunk
4747

4848
def get_chunk_url(self, chunk):
49-
return chunk["url"]
49+
url = chunk["url"]
50+
51+
if self.config.get("web_framework", None) == "django":
52+
from django.contrib.staticfiles.storage import staticfiles_storage
53+
from django.conf import settings
54+
55+
if url.startswith("http"):
56+
# webpack dev server
57+
return url
58+
else:
59+
prefix = settings.STATIC_URL
60+
url_without_static_prefix = url[
61+
url.startswith(prefix) and len(prefix) :
62+
]
63+
return staticfiles_storage.url(url_without_static_prefix)
64+
else:
65+
return url
5066

5167
def get_bundle(self, bundle_name):
5268
assets = copy.copy(self.get_assets())

0 commit comments

Comments
 (0)