Merge pull request #2846 from alecmerdler/QUAY-682

Optimize Webpack JS Bundle Size
This commit is contained in:
Alec Merdler 2017-09-18 16:47:30 -04:00 committed by GitHub
commit ad61df66c5
28 changed files with 383 additions and 366 deletions

View file

@ -24,6 +24,9 @@ from _init import __version__
logger = logging.getLogger(__name__)
JS_BUNDLE_NAME = 'bundle'
def common_login(user_uuid, permanent_session=True):
""" Performs login of the given user, with optional non-permanence on the session. """
user = model.get_user(user_uuid)
@ -56,10 +59,10 @@ def common_login(user_uuid, permanent_session=True):
return False
def _list_files(path, extension):
def _list_files(path, extension, contains=""):
""" Returns a list of all the files with the given extension found under the given path. """
def matches(f):
return os.path.splitext(f)[1] == '.' + extension and f.split(os.path.extsep)[1] != 'spec'
return os.path.splitext(f)[1] == '.' + extension and contains in os.path.splitext(f)[0]
def join_path(dp, f):
# Remove the static/ prefix. It is added in the template.
@ -71,10 +74,7 @@ def _list_files(path, extension):
def render_page_template(name, route_data=None, **kwargs):
""" Renders the page template with the given name as the response and returns its contents. """
library_styles = []
main_styles = []
library_scripts = []
main_scripts = _list_files('build', 'js')
main_scripts = _list_files('build', 'js', JS_BUNDLE_NAME)
use_cdn = app.config.get('USE_CDN', True)
if request.args.get('use_cdn') is not None:
@ -118,10 +118,7 @@ def render_page_template(name, route_data=None, **kwargs):
route_data=route_data,
external_styles=external_styles,
external_scripts=external_scripts,
main_styles=main_styles,
library_styles=library_styles,
main_scripts=main_scripts,
library_scripts=library_scripts,
feature_set=features.get_features(),
config_set=frontend_visible_config(app.config),
oauth_set=get_oauth_config(),