Implement RequireJS Optimizer in the LMS

TNL-2487
This commit is contained in:
Andy Armstrong
2015-06-23 18:49:38 -04:00
committed by cahrens
parent 80cf4d6ecb
commit 7b5f9b8009
32 changed files with 465 additions and 242 deletions

View File

@@ -1,9 +1,9 @@
"""
Settings for Bok Choy tests that are used for running CMS and LMS.
Settings for Bok Choy tests that are used when running Studio.
Bok Choy uses two different settings files:
1. test_static_optimized is used when invoking collectstatic
2. bok_choy is used when running CMS and LMS
2. bok_choy is used when running the tests
Note: it isn't possible to have a single settings file, because Django doesn't
support both generating static assets to a directory and also serving static

View File

@@ -455,7 +455,7 @@ MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
EMBARGO_SITE_REDIRECT_URL = None
############################### Pipeline #######################################
STATICFILES_STORAGE = 'cms.lib.django_require.staticstorage.OptimizedCachedRequireJsStorage'
STATICFILES_STORAGE = 'openedx.core.lib.django_require.staticstorage.OptimizedCachedRequireJsStorage'
from openedx.core.lib.rooted_paths import rooted_glob
@@ -573,7 +573,7 @@ REQUIRE_BASE_URL = "./"
# A sensible value would be 'app.build.js'. Leave blank to use the built-in default build profile.
# Set to False to disable running the default profile (e.g. if only using it to build Standalone
# Modules)
REQUIRE_BUILD_PROFILE = "build.js"
REQUIRE_BUILD_PROFILE = "cms/js/build.js"
# The name of the require.js script used by your project, relative to REQUIRE_BASE_URL.
REQUIRE_JS = "js/vendor/require.js"
@@ -592,6 +592,8 @@ REQUIRE_EXCLUDE = ("build.txt",)
# It can also be a path to a custom class that subclasses require.environments.Environment and defines some "args" function that returns a list with the command arguments to execute.
REQUIRE_ENVIRONMENT = "node"
################################# TENDER ######################################
# If you want to enable Tender integration (http://tenderapp.com/),
# put in the subdomain where Tender hosts tender_widget.js. For example,
# if you want to use the URL https://example.tenderapp.com/tender_widget.js,

View File

@@ -29,6 +29,9 @@ TEST_ROOT = REPO_ROOT / "test_root" # pylint: disable=no-value-for-parameter
# Enable debug so that static assets are served by Django
DEBUG = True
# Set REQUIRE_DEBUG to false so that it behaves like production
REQUIRE_DEBUG = False
# Serve static files at /static directly from the staticfiles directory under test root.
# Note: optimized files for testing are generated with settings from test_static_optimized
STATIC_URL = "/static/"

View File

@@ -33,3 +33,4 @@ STATIC_ROOT = (TEST_ROOT / "staticfiles" / "cms").abspath()
# 1. Uglify is by far the slowest part of the build process
# 2. Having full source code makes debugging tests easier for developers
os.environ['REQUIRE_BUILD_PROFILE_OPTIMIZE'] = 'none'
PIPELINE_JS_COMPRESSOR = None

View File

@@ -1,13 +0,0 @@
"""
:class:`~django_require.staticstorage.OptimizedCachedRequireJsStorage`
"""
from pipeline.storage import PipelineCachedStorage
from require.storage import OptimizedFilesMixin
class OptimizedCachedRequireJsStorage(OptimizedFilesMixin, PipelineCachedStorage):
"""
Custom storage backend that is used by Django-require.
"""
pass

View File

@@ -1,19 +1,21 @@
(function () {
'use strict';
var commonLibrariesPath = 'common/js/common_libraries';
var getModule = function (moduleName, excludeCommonDeps) {
var module = {
name: moduleName
};
if (excludeCommonDeps) {
module.exclude = ['js/factories/common_deps'];
module.exclude = [commonLibrariesPath];
}
return module;
};
var getModulesList = function (modules) {
var result = [getModule('js/factories/common_deps')];
var result = [getModule(commonLibrariesPath)];
return result.concat(modules.map(function (moduleName) {
return getModule(moduleName, true);
}));
@@ -84,6 +86,17 @@
'tender': 'empty:',
'youtube': 'empty:'
},
/**
* Inline requireJS text templates.
*/
inlineText: true,
/**
* Stub out requireJS text in the optimized file, but leave available for non-optimized development use.
*/
stubModules: ["text"],
/**
* If shim config is used in the app during runtime, duplicate the config
* here. Necessary if shim config is used, so that the shim's dependencies

View File

@@ -1 +0,0 @@
define(['domReady!', 'jquery', 'backbone', 'underscore', 'gettext', 'text']);

View File

@@ -36,7 +36,7 @@ import json
</head>
<body class="${static.dir_rtl()} <%block name='bodyclass'></%block> lang_${LANGUAGE_CODE}">
<%block name="view_notes"></%block>
<%block name="view_notes"></%block>
<a class="nav-skip" href="#content">${_("Skip to main content")}</a>
@@ -46,7 +46,7 @@ import json
var require = {baseUrl: window.baseUrl};
</script>
<script type="text/javascript" src="${static.url("js/vendor/require.js")}"></script>
<script type="text/javascript" src="${static.url("require-config.js")}"></script>
<script type="text/javascript" src="${static.url("cms/js/require-config.js")}"></script>
## js templates
<script id="system-feedback-tpl" type="text/template">
@@ -81,7 +81,7 @@ import json
<%block name="jsextra"></%block>
<script type="text/javascript">
require(['js/factories/common_deps'], function () {
require(['common/js/common_libraries'], function () {
require(['js/factories/base'], function () {
% if context_course:
require(['js/factories/course'], function(CourseFactory) {