django-webpack-loader
django-webpack-loader copied to clipboard
Read stats.json from DB
It's would be really nice to have option to "upload" stats.json to project db, to avoid deploying static file to multiple servers.
We have multiple servers and want to avoid removing server from production for updating stats.json file w/ RPM (our deploy).
IMO the ideal way is to ship the stats file as part of the code. On every update we ship the code to servers anyway so why not include the manifest as part of the build. This makes it part of the releases and hence rollback.
That said, I understand this is not ideal or desired in all situations. I'd like to change the inner code a little to expose most functionality implemented as a python class. Then settings can point to this class with a config like WEBPACK_LOADER_CLASS = 'webpack_loader.loader.DefaultLoader'.
Users can then extend this class and customize the loader however they want including reading of stats files.
We want to ship updated assets without touching API (some JS bugfix, styles update and etc.)
All server (eg api) related tasks are deployed via feature switch, so we don't need to wait for API to be implemented, we just ship features and switch them on, when needed.
OK. A loader class you can override should be enough to do it.
I deploy my production builds to a CDN, with a version I'd like to be able to just specify the version, and load the stats file from a known location on the CDN. The stats file can be configured to use a CDN location as the file location, so everything just loads from CDN, based on the 'version'.
The Version can be specified in the main configuration or the .env files
NOTE - your solution of adding a loader class would support this approach.
@kutenai like that?
WEBPACK_LOADER = {
'DEFAULT': {
'STATS_FILE': 'https://foo.aws3.com/bar/assets/webpack-stats.json'
}
}
yes, something like that would work, but when I look at the current code (or, current version I have), it just uses the open method, which I don't think supports a url?
def _load_assets(self):
try:
with open(self.config['STATS_FILE'], encoding="utf-8") as f:
return json.load(f)
The code is in webpack_loader.loader.py
Yes, that's why I open this issue.
Also, having hashes in file on disk looks wrong for me.
Currently we don't support opening stats files from network and probably never will but I'm open to making the loader class more extensible so we can write simple plugins to load from anywhere. Would be great if someone comes up with the design of how it would work here.