From 5772042199701235ba83a5bfb2f24f405f303230 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 25 Jan 2018 22:27:45 -0500 Subject: [PATCH] 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' ] },