Merge pull request #18902 from cpennington/fix-educator-3262-v3
Load all webpack chunks into fragments as correctly-typed resources
This commit is contained in:
@@ -149,13 +149,10 @@
|
||||
}
|
||||
} else if (mimetype === 'application/javascript') {
|
||||
if (kind === 'text') {
|
||||
eval.call(window, data);
|
||||
console.log("JavaScript text resource eval'd", resource);
|
||||
// xss-lint: disable=javascript-jquery-append,javascript-concat-html
|
||||
$head.append('<script>' + data + '</script>');
|
||||
} else if (kind === 'url') {
|
||||
// This is a dependency loaded from the LMS (not ideal)
|
||||
return ViewUtils.loadJavaScript(data).done(function() {
|
||||
console.log('JavaScript url resource loaded', resource);
|
||||
});
|
||||
$script(data, data);
|
||||
}
|
||||
} else if (mimetype === 'text/html') {
|
||||
if (placement === 'head') {
|
||||
|
||||
@@ -6,6 +6,7 @@ runtime environment with the djangoapps in common configured to load
|
||||
|
||||
# NOTE: we are importing this method so that any module that imports us has access to get_current_request
|
||||
from crum import get_current_request
|
||||
import webpack_loader
|
||||
|
||||
|
||||
def get_current_request_hostname():
|
||||
@@ -18,3 +19,14 @@ def get_current_request_hostname():
|
||||
hostname = request.META.get('HTTP_HOST')
|
||||
|
||||
return hostname
|
||||
|
||||
|
||||
def add_webpack_to_fragment(fragment, bundle_name, extension=None, config='DEFAULT'):
|
||||
"""
|
||||
Add all webpack chunks to the supplied fragment as the appropriate resource type.
|
||||
"""
|
||||
for chunk in webpack_loader.utils.get_files(bundle_name, extension, config):
|
||||
if chunk['name'].endswith(('.js', '.js.gz')):
|
||||
fragment.add_javascript_url(chunk['url'])
|
||||
elif chunk['name'].endswith(('.css', '.css.gz')):
|
||||
fragment.add_css_url(chunk['url'])
|
||||
|
||||
@@ -16,6 +16,7 @@ from xmodule.mako_module import MakoTemplateBlockBase
|
||||
from xmodule.progress import Progress
|
||||
from xmodule.seq_module import SequenceFields
|
||||
from xmodule.studio_editable import StudioEditableBlock
|
||||
from xmodule.util.xmodule_django import add_webpack_to_fragment
|
||||
from xmodule.x_module import STUDENT_VIEW, XModuleFields
|
||||
from xmodule.xml_module import XmlParserMixin
|
||||
|
||||
@@ -98,8 +99,7 @@ class VerticalBlock(SequenceFields, XModuleFields, StudioEditableBlock, XmlParse
|
||||
'bookmark_id': u"{},{}".format(child_context['username'], unicode(self.location)), # pylint: disable=no-member
|
||||
}))
|
||||
|
||||
for tag in webpack_loader.utils.get_as_tags('VerticalStudentView'):
|
||||
fragment.add_resource(tag, mimetype='text/html', placement='head')
|
||||
add_webpack_to_fragment(fragment, 'VerticalStudentView')
|
||||
fragment.initialize_js('VerticalStudentView')
|
||||
|
||||
return fragment
|
||||
|
||||
@@ -32,6 +32,7 @@ from xmodule import block_metadata_utils
|
||||
from xmodule.fields import RelativeTime
|
||||
from xmodule.errortracker import exc_info_to_str
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError
|
||||
from xmodule.util.xmodule_django import add_webpack_to_fragment
|
||||
|
||||
from opaque_keys.edx.keys import UsageKey
|
||||
from opaque_keys.edx.asides import AsideUsageKeyV2, AsideDefinitionKeyV2
|
||||
@@ -260,8 +261,7 @@ def shim_xmodule_js(block, fragment):
|
||||
fragment.initialize_js('XBlockToXModuleShim')
|
||||
fragment.json_init_args = {'xmodule-type': block.js_module_name}
|
||||
|
||||
for tag in webpack_loader.utils.get_as_tags('XModuleShim'):
|
||||
fragment.add_resource(tag, mimetype='text/html', placement='head')
|
||||
add_webpack_to_fragment(fragment, 'XModuleShim')
|
||||
|
||||
|
||||
class XModuleFields(object):
|
||||
|
||||
Reference in New Issue
Block a user