Description
Problem
Currently if using a custom_domain
on something that extends S3ManifestStaticStorage
for a separate cdn for assets like cdn.example.com
and in the webpack configuration defines uses publicPath
, the custom_domain
never gets loaded:
https://github.com/django-webpack/django-webpack-loader/blob/master/webpack_loader/loaders.py#L81
Bad Solution
In Webpack, for any deployed env (like prod), one could set output: { publicPath: '', },
in the webpack config. This prevents publicPath being created for any asset in the manifest.json.
We tried this but it forces img, font assets to be inside the css folder due to the way references are built without a publicPath.
Best Work Around
Currently, we monkey patch get_chunk_url
(works perfectly well for us):
import os
from django.contrib.staticfiles.storage import staticfiles_storage
from webpack_loader.loader import WebpackLoader
def get_chunk_url(self, chunk_file):
# Removed by Monkey Patch
# public_path = chunk_file.get('publicPath')
# if public_path:
# return public_path
# Use os.path.normpath for Windows paths
relpath = os.path.normpath(
os.path.join(self.config["BUNDLE_DIR_NAME"], chunk_file["name"])
)
return staticfiles_storage.url(relpath)
WebpackLoader.get_chunk_url = get_chunk_url
Solution
Honestly, I don't know what a good solution is here? Possible:
- Carry a variable
render_bundle
? Seems very distant. settings.WEBPACK_USE_PUBLICPATH_FROM_CHUNK_FILE
- feels like the best of poisons?