From 5772042199701235ba83a5bfb2f24f405f303230 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 25 Jan 2018 22:27:45 -0500 Subject: [PATCH 1/2] Migrate login.js to webpack --- cms/static/cms/js/build.js | 1 - cms/static/js/pages/login.js | 17 +++---- cms/templates/base.html | 45 ++++++++++--------- cms/templates/login.html | 2 +- .../templates/static_content.html | 9 +--- .../test/test-theme/cms/templates/login.html | 2 +- themes/red-theme/cms/templates/login.html | 2 +- webpack.common.config.js | 16 +++++-- 8 files changed, 46 insertions(+), 48 deletions(-) diff --git a/cms/static/cms/js/build.js b/cms/static/cms/js/build.js index d0221be3a9..3f86a8c891 100644 --- a/cms/static/cms/js/build.js +++ b/cms/static/cms/js/build.js @@ -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', diff --git a/cms/static/js/pages/login.js b/cms/static/js/pages/login.js index 8c53644675..8caff6a833 100644 --- a/cms/static/js/pages/login.js +++ b/cms/static/js/pages/login.js @@ -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); + } +); diff --git a/cms/templates/base.html b/cms/templates/base.html index 1736677f2a..631db5a72a 100644 --- a/cms/templates/base.html +++ b/cms/templates/base.html @@ -121,29 +121,30 @@ from openedx.core.djangolib.markup import HTML <%block name="modal_placeholder"> <%block name="jsextra"> - - <%block name='requirejs_page'> + <%include file="widgets/segment-io-footer.html" /> diff --git a/cms/templates/login.html b/cms/templates/login.html index 7981ae6dc4..eaa0a1940b 100644 --- a/cms/templates/login.html +++ b/cms/templates/login.html @@ -54,7 +54,7 @@ from openedx.core.djangolib.js_utils import js_escaped_string -<%block name="requirejs_page"> +<%block name="page_bundle"> <%static:require_page page_name="js/pages/login" class_name="LoginFactory"> "${reverse('homepage') | n, js_escaped_string}" diff --git a/common/djangoapps/pipeline_mako/templates/static_content.html b/common/djangoapps/pipeline_mako/templates/static_content.html index 68e3cd6175..492926aece 100644 --- a/common/djangoapps/pipeline_mako/templates/static_content.html +++ b/common/djangoapps/pipeline_mako/templates/static_content.html @@ -174,14 +174,7 @@ source, template_path = Loader(engine).load_template_source(path) pageFactoryArguments['${class_name | n, js_escaped_string}'] = []; % endif - % if not settings.REQUIRE_DEBUG: - - % endif - + <%self:webpack entry="${page_name}"/> <%def name="require_module(module_name, class_name)"> diff --git a/common/test/test-theme/cms/templates/login.html b/common/test/test-theme/cms/templates/login.html index 8479674153..496f0e9032 100644 --- a/common/test/test-theme/cms/templates/login.html +++ b/common/test/test-theme/cms/templates/login.html @@ -52,7 +52,7 @@ from openedx.core.djangolib.js_utils import js_escaped_string -<%block name="requirejs_page"> +<%block name="page_bundle"> <%static:require_page page_name="js/pages/login" class_name="LoginFactory"> "${reverse('homepage') | n, js_escaped_string}" diff --git a/themes/red-theme/cms/templates/login.html b/themes/red-theme/cms/templates/login.html index b50ed21855..b7318c1e88 100644 --- a/themes/red-theme/cms/templates/login.html +++ b/themes/red-theme/cms/templates/login.html @@ -51,7 +51,7 @@ from django.utils.translation import ugettext as _ -<%block name="requirejs_page"> +<%block name="page_bundle"> <%static:require_page page_name="js/pages/login" class_name="LoginFactory"> "${reverse('homepage') | n, js_escaped_string}" diff --git a/webpack.common.config.js b/webpack.common.config.js index 2409a81a68..f06e7463ab 100644 --- a/webpack.common.config.js +++ b/webpack.common.config.js @@ -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' ] }, From b701ad77c8cbc5a4a22bd5f8c6c8bab04f727632 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 26 Jan 2018 10:27:33 -0500 Subject: [PATCH 2/2] Rename require_page to invoke_page_bundle --- cms/templates/login.html | 4 ++-- common/djangoapps/pipeline_mako/templates/static_content.html | 2 +- common/static/common/js/utils/page_factory.js | 4 ++-- common/test/test-theme/cms/templates/login.html | 4 ++-- scripts/xss_linter.py | 4 ++-- themes/red-theme/cms/templates/login.html | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cms/templates/login.html b/cms/templates/login.html index eaa0a1940b..c4966f8b66 100644 --- a/cms/templates/login.html +++ b/cms/templates/login.html @@ -55,7 +55,7 @@ from openedx.core.djangolib.js_utils import js_escaped_string <%block name="page_bundle"> - <%static:require_page page_name="js/pages/login" class_name="LoginFactory"> + <%static:invoke_page_bundle page_name="js/pages/login" class_name="LoginFactory"> "${reverse('homepage') | n, js_escaped_string}" - + diff --git a/common/djangoapps/pipeline_mako/templates/static_content.html b/common/djangoapps/pipeline_mako/templates/static_content.html index 492926aece..56593458f5 100644 --- a/common/djangoapps/pipeline_mako/templates/static_content.html +++ b/common/djangoapps/pipeline_mako/templates/static_content.html @@ -154,7 +154,7 @@ source, template_path = Loader(engine).load_template_source(path) -<%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. diff --git a/common/static/common/js/utils/page_factory.js b/common/static/common/js/utils/page_factory.js index 8b3e72c827..3ae02bca25 100644 --- a/common/static/common/js/utils/page_factory.js +++ b/common/static/common/js/utils/page_factory.js @@ -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]); diff --git a/common/test/test-theme/cms/templates/login.html b/common/test/test-theme/cms/templates/login.html index 496f0e9032..4e13b5cdc9 100644 --- a/common/test/test-theme/cms/templates/login.html +++ b/common/test/test-theme/cms/templates/login.html @@ -53,7 +53,7 @@ from openedx.core.djangolib.js_utils import js_escaped_string <%block name="page_bundle"> - <%static:require_page page_name="js/pages/login" class_name="LoginFactory"> + <%static:invoke_page_bundle page_name="js/pages/login" class_name="LoginFactory"> "${reverse('homepage') | n, js_escaped_string}" - + diff --git a/scripts/xss_linter.py b/scripts/xss_linter.py index d1d0fe0d07..985bc44761 100755 --- a/scripts/xss_linter.py +++ b/scripts/xss_linter.py @@ -2383,8 +2383,8 @@ class MakoTemplateLinter(BaseLinter): | # script tag end <%static:require_module(_async)?.*?> | # require js script tag start (optionally the _async version) | # require js script tag end (optionally the _async version) - <%static:require_page.*?> | # require js script tag start - | # require js script tag end + <%static:invoke_page_bundle.*?> | # require js script tag start + | # require js script tag end <%static:webpack.*?> | # webpack script tag start | # webpack script tag end <%static:studiofrontend.*?> | # studiofrontend script tag start diff --git a/themes/red-theme/cms/templates/login.html b/themes/red-theme/cms/templates/login.html index b7318c1e88..721104311d 100644 --- a/themes/red-theme/cms/templates/login.html +++ b/themes/red-theme/cms/templates/login.html @@ -52,7 +52,7 @@ from django.utils.translation import ugettext as _ <%block name="page_bundle"> - <%static:require_page page_name="js/pages/login" class_name="LoginFactory"> + <%static:invoke_page_bundle page_name="js/pages/login" class_name="LoginFactory"> "${reverse('homepage') | n, js_escaped_string}" - +