Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions webpack_boilerplate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def load_from_django():
user_config = dict(DEFAULT_CONFIG, **getattr(settings, "WEBPACK_LOADER", {}))

user_config["ignores"] = [re.compile(I) for I in user_config["IGNORE"]]
user_config["web_framework"] = "django"
return user_config


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

user_config["ignores"] = [re.compile(I) for I in user_config["IGNORE"]]
user_config["web_framework"] = "flask"
return user_config


Expand Down
18 changes: 17 additions & 1 deletion webpack_boilerplate/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,23 @@ def filter_chunks(self, chunks):
yield chunk

def get_chunk_url(self, chunk):
return chunk["url"]
url = chunk["url"]

if self.config.get("web_framework", None) == "django":
from django.contrib.staticfiles.storage import staticfiles_storage
from django.conf import settings

if url.startswith("http"):
# webpack dev server
return url
else:
prefix = settings.STATIC_URL
url_without_static_prefix = url[
url.startswith(prefix) and len(prefix) :
]
return staticfiles_storage.url(url_without_static_prefix)
else:
return url

def get_bundle(self, bundle_name):
assets = copy.copy(self.get_assets())
Expand Down