Merge pull request #17316 from cpennington/switch-cms-login-to-webpack

Migrate login.js to webpack
This commit is contained in:
Calen Pennington
2018-01-30 14:24:08 -05:00
committed by GitHub
10 changed files with 57 additions and 59 deletions

View File

@@ -28,7 +28,6 @@
'js/certificates/factories/certificates_page_factory',
'js/factories/index',
'js/factories/library',
'js/pages/login',
'js/factories/manage_users',
'js/factories/outline',
'js/factories/register',

View File

@@ -1,11 +1,8 @@
(function(define) {
'use strict';
define(
['js/factories/login', 'common/js/utils/page_factory'],
function(LoginFactory, invokePageFactory) {
invokePageFactory('LoginFactory', LoginFactory);
}
);
}).call(this, define || RequireJS.define);
define(
['js/factories/login', 'common/js/utils/page_factory'],
function(LoginFactory, invokePageFactory) {
'use strict';
invokePageFactory('LoginFactory', LoginFactory);
}
);

View File

@@ -121,29 +121,30 @@ from openedx.core.djangolib.markup import HTML
<%block name="modal_placeholder"></%block>
<%block name="jsextra"></%block>
<script type="text/javascript">
require(['js/factories/base'], function () {
require(['js/models/course'], function(Course) {
% if context_course:
window.course = new Course({
id: "${context_course.id | n, js_escaped_string}",
name: "${context_course.display_name_with_default | n, js_escaped_string}",
url_name: "${context_course.location.block_id | n, js_escaped_string}",
org: "${context_course.location.org | n, js_escaped_string}",
num: "${context_course.location.course | n, js_escaped_string}",
display_course_number: "${context_course.display_coursenumber | n, js_escaped_string}",
revision: "${context_course.location.branch | n, js_escaped_string}",
self_paced: ${context_course.self_paced | n, dump_js_escaped_json}
});
% endif
% if user.is_authenticated():
require(['js/sock']);
% endif
<%block name='requirejs'></%block>
});
});
<%block name="page_bundle">
<script type="text/javascript">
require(['js/factories/base'], function () {
require(['js/models/course'], function(Course) {
% if context_course:
window.course = new Course({
id: "${context_course.id | n, js_escaped_string}",
name: "${context_course.display_name_with_default | n, js_escaped_string}",
url_name: "${context_course.location.block_id | n, js_escaped_string}",
org: "${context_course.location.org | n, js_escaped_string}",
num: "${context_course.location.course | n, js_escaped_string}",
display_course_number: "${context_course.display_coursenumber | n, js_escaped_string}",
revision: "${context_course.location.branch | n, js_escaped_string}",
self_paced: ${context_course.self_paced | n, dump_js_escaped_json}
});
% endif
% if user.is_authenticated():
require(['js/sock']);
% endif
<%block name='requirejs'></%block>
});
});
</script>
<%block name='requirejs_page'></%block>
</%block>
<%include file="widgets/segment-io-footer.html" />
<div class="modal-cover"></div>
</body>

View File

@@ -54,8 +54,8 @@ from openedx.core.djangolib.js_utils import js_escaped_string
</div>
</%block>
<%block name="requirejs_page">
<%static:require_page page_name="js/pages/login" class_name="LoginFactory">
<%block name="page_bundle">
<%static:invoke_page_bundle page_name="js/pages/login" class_name="LoginFactory">
"${reverse('homepage') | n, js_escaped_string}"
</%static:require_page>
</%static:invoke_page_bundle>
</%block>

View File

@@ -154,7 +154,7 @@ source, template_path = Loader(engine).load_template_source(path)
</script>
</%def>
<%def name="require_page(page_name, class_name)">
<%def name="invoke_page_bundle(page_name, class_name)">
<%doc>
Loads Javascript onto your page synchronously.
Uses RequireJS in development and a plain script tag in production.
@@ -174,14 +174,7 @@ source, template_path = Loader(engine).load_template_source(path)
pageFactoryArguments['${class_name | n, js_escaped_string}'] = [];
% endif
</script>
% if not settings.REQUIRE_DEBUG:
<script type="text/javascript" src="${staticfiles_storage.url(page_name + '.js') + '?raw'}"></script>
% endif
<script type="text/javascript">
(function (require) {
require(['${page_name | n, js_escaped_string}']);
}).call(this, require || RequireJS.require);
</script>
<%self:webpack entry="${page_name}"/>
</%def>
<%def name="require_module(module_name, class_name)">

View File

@@ -8,7 +8,7 @@ define([], function() {
throw Error(
'window.pageFactoryArguments must be initialized before calling invokePageFactory(' +
name +
'). Use the <%static:require_page> template tag.'
'). Use the <%static:invoke_page_bundle> template tag.'
);
}
args = window.pageFactoryArguments[name];
@@ -19,7 +19,7 @@ define([], function() {
name +
'"] must be initialized before calling invokePageFactory(' +
name +
'). Use the <%static:require_page> template tag.'
'). Use the <%static:invoke_page_bundle> template tag.'
);
}
factory.apply(null, window.pageFactoryArguments[name]);

View File

@@ -52,8 +52,8 @@ from openedx.core.djangolib.js_utils import js_escaped_string
</div>
</%block>
<%block name="requirejs_page">
<%static:require_page page_name="js/pages/login" class_name="LoginFactory">
<%block name="page_bundle">
<%static:invoke_page_bundle page_name="js/pages/login" class_name="LoginFactory">
"${reverse('homepage') | n, js_escaped_string}"
</%static:require_page>
</%static:invoke_page_bundle>
</%block>

View File

@@ -2383,8 +2383,8 @@ class MakoTemplateLinter(BaseLinter):
</script> | # script tag end
<%static:require_module(_async)?.*?> | # require js script tag start (optionally the _async version)
</%static:require_module(_async)?> | # require js script tag end (optionally the _async version)
<%static:require_page.*?> | # require js script tag start
</%static:require_page> | # require js script tag end
<%static:invoke_page_bundle.*?> | # require js script tag start
</%static:invoke_page_bundle> | # require js script tag end
<%static:webpack.*?> | # webpack script tag start
</%static:webpack> | # webpack script tag end
<%static:studiofrontend.*?> | # studiofrontend script tag start

View File

@@ -51,8 +51,8 @@ from django.utils.translation import ugettext as _
</div>
</%block>
<%block name="requirejs_page">
<%static:require_page page_name="js/pages/login" class_name="LoginFactory">
<%block name="page_bundle">
<%static:invoke_page_bundle page_name="js/pages/login" class_name="LoginFactory">
"${reverse('homepage') | n, js_escaped_string}"
</%static:require_page>
</%static:invoke_page_bundle>
</%block>

View File

@@ -9,9 +9,14 @@ var StringReplace = require('string-replace-webpack-plugin');
var namespacedRequireFiles = [
path.resolve(__dirname, 'common/static/common/js/components/views/feedback_notification.js'),
path.resolve(__dirname, 'common/static/common/js/components/views/feedback.js')
path.resolve(__dirname, 'common/static/common/js/components/views/feedback_prompt.js'),
path.resolve(__dirname, 'common/static/common/js/components/views/feedback.js'),
path.resolve(__dirname, 'common/static/common/js/components/utils/view_utils.js')
];
var defineHeader = /\(function ?\(define(, require)?\) ?\{/;
var defineFooter = /\}\)\.call\(this, define \|\| RequireJS\.define(, require \|\| RequireJS\.require)?\);/;
module.exports = {
context: __dirname,
@@ -21,6 +26,7 @@ module.exports = {
Import: './cms/static/js/features/import/factories/import.js',
CourseOrLibraryListing: './cms/static/js/features_jsx/studio/CourseOrLibraryListing.jsx',
AccessibilityPage: './node_modules/@edx/studio-frontend/src/accessibilityIndex.jsx',
'js/pages/login': './cms/static/js/pages/login.js',
// LMS
SingleSupportForm: './lms/static/support/jsx/single_support_form.jsx',
@@ -98,11 +104,11 @@ module.exports = {
{
replacements: [
{
pattern: /\(function ?\(define\) ?\{/,
pattern: defineHeader,
replacement: function() { return ''; }
},
{
pattern: /\}\)\.call\(this, define \|\| RequireJS\.define\);/,
pattern: defineFooter,
replacement: function() { return ''; }
}
]
@@ -168,7 +174,9 @@ module.exports = {
},
modules: [
'node_modules',
'common/static/js/vendor/'
'common/static/js/vendor/',
'cms/static',
'common/static/js/src'
]
},