|
3 | 3 | from __future__ import absolute_import
|
4 | 4 | from pytz import timezone, UTC
|
5 | 5 | from flask import g, Blueprint, request, current_app
|
| 6 | +import json |
6 | 7 | from coaster.assets import split_namespec
|
7 | 8 | from flask_assets import Environment, Bundle
|
8 | 9 | from flask_caching import Cache
|
@@ -172,6 +173,23 @@ def init_app(self, app, requires=[], ext_requires=[], bundle_js=None, bundle_css
|
172 | 173 | app.assets.register('css_all', css_all)
|
173 | 174 | app.register_blueprint(self, static_subdomain=subdomain)
|
174 | 175 |
|
| 176 | + # Optional config for a client app to use a manifest file |
| 177 | + # to load fingerprinted assets |
| 178 | + # If used with webpack, the client app is expected to specify its own webpack.config.js |
| 179 | + # Set `ASSETS_MANIFEST_PATH` in `app.config` to the path for `manifest.json`. |
| 180 | + # Eg: "static/build/manifest.json" |
| 181 | + # Set `ASSET_BASE_PATH` in `app.config` to the path in which the compiled assets are present. |
| 182 | + # Eg: "static/build" |
| 183 | + if app.config.get('ASSET_MANIFEST_PATH'): |
| 184 | + # Load assets into config from a manifest file |
| 185 | + with app.open_resource(app.config['ASSET_MANIFEST_PATH']) as f: |
| 186 | + asset_bundles = json.loads(f.read()) |
| 187 | + if app.config.get('assets'): |
| 188 | + raise ValueError("Loading assets via a manifest file needs the `ASSETS` config key to be unused") |
| 189 | + app.config['assets'] = {} |
| 190 | + for asset_key, asset_path in asset_bundles['assets'].items(): |
| 191 | + app.config['assets'][asset_key] = asset_path |
| 192 | + |
175 | 193 | app.config.setdefault('CACHE_KEY_PREFIX', 'flask_cache_' + app.name + '/')
|
176 | 194 | nwcacheconfig = dict(app.config)
|
177 | 195 | nwcacheconfig['CACHE_KEY_PREFIX'] = 'networkbar_'
|
|
0 commit comments