Implement RequireJS Optimizer in the LMS
TNL-2487
This commit is contained in:
137
lms/static/lms/js/build.js
Normal file
137
lms/static/lms/js/build.js
Normal file
@@ -0,0 +1,137 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var getModulesList = function (modules) {
|
||||
return modules.map(function (moduleName) {
|
||||
return { name: moduleName };
|
||||
});
|
||||
};
|
||||
|
||||
var jsOptimize = process.env.REQUIRE_BUILD_PROFILE_OPTIMIZE !== undefined ?
|
||||
process.env.REQUIRE_BUILD_PROFILE_OPTIMIZE : 'uglify2';
|
||||
|
||||
return {
|
||||
namespace: "RequireJS",
|
||||
/**
|
||||
* List the modules that will be optimized. All their immediate and deep
|
||||
* dependencies will be included in the module's file when the build is
|
||||
* done.
|
||||
*/
|
||||
modules: getModulesList([
|
||||
'teams/js/teams_tab_factory'
|
||||
]),
|
||||
|
||||
/**
|
||||
* By default all the configuration for optimization happens from the command
|
||||
* line or by properties in the config file, and configuration that was
|
||||
* passed to requirejs as part of the app's runtime "main" JS file is *not*
|
||||
* considered. However, if you prefer the "main" JS file configuration
|
||||
* to be read for the build so that you do not have to duplicate the values
|
||||
* in a separate configuration, set this property to the location of that
|
||||
* main JS file. The first requirejs({}), require({}), requirejs.config({}),
|
||||
* or require.config({}) call found in that file will be used.
|
||||
* As of 2.1.10, mainConfigFile can be an array of values, with the last
|
||||
* value's config take precedence over previous values in the array.
|
||||
*/
|
||||
mainConfigFile: 'require-config.js',
|
||||
/**
|
||||
* Set paths for modules. If relative paths, set relative to baseUrl above.
|
||||
* If a special value of "empty:" is used for the path value, then that
|
||||
* acts like mapping the path to an empty file. It allows the optimizer to
|
||||
* resolve the dependency to path, but then does not include it in the output.
|
||||
* Useful to map module names that are to resources on a CDN or other
|
||||
* http: URL when running in the browser and during an optimization that
|
||||
* file should be skipped because it has no dependencies.
|
||||
*/
|
||||
paths: {
|
||||
'gettext': 'empty:',
|
||||
'coffee/src/ajax_prefix': 'empty:',
|
||||
'jquery': 'empty:',
|
||||
'jquery.cookie': 'empty:',
|
||||
'jquery.url': 'empty:',
|
||||
'backbone': 'empty:',
|
||||
'underscore': 'empty:',
|
||||
'logger': 'empty:',
|
||||
'utility': 'empty:',
|
||||
'URI': '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
|
||||
* are included in the build. Using "mainConfigFile" is a better way to
|
||||
* pass this information though, so that it is only listed in one place.
|
||||
* However, if mainConfigFile is not an option, the shim config can be
|
||||
* inlined in the build config.
|
||||
*/
|
||||
shim: {},
|
||||
/**
|
||||
* Introduced in 2.1.2: If using "dir" for an output directory, normally the
|
||||
* optimize setting is used to optimize the build bundles (the "modules"
|
||||
* section of the config) and any other JS file in the directory. However, if
|
||||
* the non-build bundle JS files will not be loaded after a build, you can
|
||||
* skip the optimization of those files, to speed up builds. Set this value
|
||||
* to true if you want to skip optimizing those other non-build bundle JS
|
||||
* files.
|
||||
*/
|
||||
skipDirOptimize: true,
|
||||
/**
|
||||
* When the optimizer copies files from the source location to the
|
||||
* destination directory, it will skip directories and files that start
|
||||
* with a ".". If you want to copy .directories or certain .files, for
|
||||
* instance if you keep some packages in a .packages directory, or copy
|
||||
* over .htaccess files, you can set this to null. If you want to change
|
||||
* the exclusion rules, change it to a different regexp. If the regexp
|
||||
* matches, it means the directory will be excluded. This used to be
|
||||
* called dirExclusionRegExp before the 1.0.2 release.
|
||||
* As of 1.0.3, this value can also be a string that is converted to a
|
||||
* RegExp via new RegExp().
|
||||
*/
|
||||
fileExclusionRegExp: /^\.|spec|spec_helpers/,
|
||||
/**
|
||||
* Allow CSS optimizations. Allowed values:
|
||||
* - "standard": @import inlining and removal of comments, unnecessary
|
||||
* whitespace and line returns.
|
||||
* Removing line returns may have problems in IE, depending on the type
|
||||
* of CSS.
|
||||
* - "standard.keepLines": like "standard" but keeps line returns.
|
||||
* - "none": skip CSS optimizations.
|
||||
* - "standard.keepComments": keeps the file comments, but removes line
|
||||
* returns. (r.js 1.0.8+)
|
||||
* - "standard.keepComments.keepLines": keeps the file comments and line
|
||||
* returns. (r.js 1.0.8+)
|
||||
* - "standard.keepWhitespace": like "standard" but keeps unnecessary whitespace.
|
||||
*/
|
||||
optimizeCss: 'none',
|
||||
/**
|
||||
* How to optimize all the JS files in the build output directory.
|
||||
* Right now only the following values are supported:
|
||||
* - "uglify": Uses UglifyJS to minify the code.
|
||||
* - "uglify2": Uses UglifyJS2.
|
||||
* - "closure": Uses Google's Closure Compiler in simple optimization
|
||||
* mode to minify the code. Only available if REQUIRE_ENVIRONMENT is "rhino" (the default).
|
||||
* - "none": No minification will be done.
|
||||
*/
|
||||
optimize: jsOptimize,
|
||||
/**
|
||||
* Sets the logging level. It is a number:
|
||||
* TRACE: 0,
|
||||
* INFO: 1,
|
||||
* WARN: 2,
|
||||
* ERROR: 3,
|
||||
* SILENT: 4
|
||||
* Default is 0.
|
||||
*/
|
||||
logLevel: 1
|
||||
};
|
||||
} ())
|
||||
185
lms/static/lms/js/require-config.js
Normal file
185
lms/static/lms/js/require-config.js
Normal file
@@ -0,0 +1,185 @@
|
||||
;(function (require, define) {
|
||||
|
||||
// We do not wish to bundle common libraries (that may also be used by non-RequireJS code on the page
|
||||
// into the optimized files. Therefore load these libraries through script tags and explicitly define them.
|
||||
// Note that when the optimizer executes this code, window will not be defined.
|
||||
if (window) {
|
||||
var defineDependency = function (globalVariable, name, noShim) {
|
||||
if (window[globalVariable]) {
|
||||
if (noShim) {
|
||||
define(name, {});
|
||||
}
|
||||
else {
|
||||
define(name, [], function() {return window[globalVariable];});
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.error("Expected library to be included on page, but not found on window object: " + name);
|
||||
}
|
||||
};
|
||||
defineDependency("jQuery", "jquery");
|
||||
defineDependency("_", "underscore");
|
||||
defineDependency("gettext", "gettext");
|
||||
defineDependency("Logger", "logger");
|
||||
defineDependency("URI", "URI");
|
||||
defineDependency("Backbone", "backbone");
|
||||
// utility.js adds two functions to the window object, but does not return anything
|
||||
defineDependency("isExternal", "utility", true);
|
||||
}
|
||||
|
||||
require.config({
|
||||
// NOTE: baseUrl has been previously set in lms/templates/main.html
|
||||
waitSeconds: 60,
|
||||
paths: {
|
||||
"gettext": "/i18n",
|
||||
"annotator_1.2.9": "js/vendor/edxnotes/annotator-full.min",
|
||||
"date": "js/vendor/date",
|
||||
"text": "js/vendor/requirejs/text",
|
||||
"logger": "js/src/logger",
|
||||
"backbone": "js/vendor/backbone-min",
|
||||
"backbone-super": "js/vendor/backbone-super",
|
||||
"backbone.paginator": "js/vendor/backbone.paginator.min",
|
||||
"underscore": "js/vendor/underscore-min",
|
||||
"underscore.string": "js/vendor/underscore.string.min",
|
||||
"jquery": "js/vendor/jquery.min",
|
||||
"jquery.cookie": "js/vendor/jquery.cookie",
|
||||
"jquery.url": "js/vendor/url.min",
|
||||
"jquery.ui": "js/vendor/jquery-ui.min",
|
||||
"jquery.iframe-transport": "js/vendor/jQuery-File-Upload/js/jquery.iframe-transport",
|
||||
"jquery.fileupload": "js/vendor/jQuery-File-Upload/js/jquery.fileupload",
|
||||
"URI": "js/vendor/URI.min",
|
||||
"string_utils": "js/src/string_utils",
|
||||
"utility": "js/src/utility",
|
||||
|
||||
// Files needed by OVA
|
||||
"annotator": "js/vendor/ova/annotator-full",
|
||||
"annotator-harvardx": "js/vendor/ova/annotator-full-firebase-auth",
|
||||
"video.dev": "js/vendor/ova/video.dev",
|
||||
"vjs.youtube": "js/vendor/ova/vjs.youtube",
|
||||
"rangeslider": "js/vendor/ova/rangeslider",
|
||||
"share-annotator": "js/vendor/ova/share-annotator",
|
||||
"richText-annotator": "js/vendor/ova/richText-annotator",
|
||||
"reply-annotator": "js/vendor/ova/reply-annotator",
|
||||
"grouping-annotator": "js/vendor/ova/grouping-annotator",
|
||||
"tags-annotator": "js/vendor/ova/tags-annotator",
|
||||
"diacritic-annotator": "js/vendor/ova/diacritic-annotator",
|
||||
"flagging-annotator": "js/vendor/ova/flagging-annotator",
|
||||
"jquery-Watch": "js/vendor/ova/jquery-Watch",
|
||||
"openseadragon": "js/vendor/ova/openseadragon",
|
||||
"osda": "js/vendor/ova/OpenSeaDragonAnnotation",
|
||||
"ova": "js/vendor/ova/ova",
|
||||
"catch": "js/vendor/ova/catch/js/catch",
|
||||
"handlebars": "js/vendor/ova/catch/js/handlebars-1.1.2",
|
||||
"tinymce": "js/vendor/tinymce/js/tinymce/tinymce.full.min",
|
||||
"jquery.tinymce": "js/vendor/tinymce/js/tinymce/jquery.tinymce.min"
|
||||
// end of files needed by OVA
|
||||
},
|
||||
shim: {
|
||||
"gettext": {
|
||||
exports: "gettext"
|
||||
},
|
||||
"annotator_1.2.9": {
|
||||
deps: ["jquery"],
|
||||
exports: "Annotator"
|
||||
},
|
||||
"date": {
|
||||
exports: "Date"
|
||||
},
|
||||
"jquery": {
|
||||
exports: "$"
|
||||
},
|
||||
"jquery.cookie": {
|
||||
deps: ["jquery"],
|
||||
exports: "jQuery.fn.cookie"
|
||||
},
|
||||
"jquery.url": {
|
||||
deps: ["jquery"],
|
||||
exports: "jQuery.url"
|
||||
},
|
||||
"jquery.fileupload": {
|
||||
deps: ["jquery.ui", "jquery.iframe-transport"],
|
||||
exports: "jQuery.fn.fileupload"
|
||||
},
|
||||
"jquery.tinymce": {
|
||||
deps: ["jquery", "tinymce"],
|
||||
exports: "jQuery.fn.tinymce"
|
||||
},
|
||||
"underscore": {
|
||||
exports: "_"
|
||||
},
|
||||
"backbone": {
|
||||
deps: ["underscore", "jquery"],
|
||||
exports: "Backbone"
|
||||
},
|
||||
"backbone.paginator": {
|
||||
deps: ["backbone"],
|
||||
exports: "Backbone.Paginator"
|
||||
},
|
||||
"backbone-super": {
|
||||
deps: ["backbone"]
|
||||
},
|
||||
"string_utils": {
|
||||
deps: ["underscore"],
|
||||
exports: "interpolate_text"
|
||||
},
|
||||
// Needed by OVA
|
||||
"video.dev": {
|
||||
exports:"videojs"
|
||||
},
|
||||
"vjs.youtube": {
|
||||
deps: ["video.dev"]
|
||||
},
|
||||
"rangeslider": {
|
||||
deps: ["video.dev"]
|
||||
},
|
||||
"annotator": {
|
||||
exports: "Annotator"
|
||||
},
|
||||
"annotator-harvardx":{
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"share-annotator": {
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"richText-annotator": {
|
||||
deps: ["annotator", "tinymce"]
|
||||
},
|
||||
"reply-annotator": {
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"tags-annotator": {
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"diacritic-annotator": {
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"flagging-annotator": {
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"grouping-annotator": {
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"ova": {
|
||||
exports: "ova",
|
||||
deps: [
|
||||
"annotator", "annotator-harvardx", "video.dev", "vjs.youtube", "rangeslider", "share-annotator",
|
||||
"richText-annotator", "reply-annotator", "tags-annotator", "flagging-annotator",
|
||||
"grouping-annotator", "diacritic-annotator", "jquery-Watch", "catch", "handlebars", "URI"
|
||||
]
|
||||
},
|
||||
"osda": {
|
||||
exports: "osda",
|
||||
deps: [
|
||||
"annotator", "annotator-harvardx", "video.dev", "vjs.youtube", "rangeslider", "share-annotator",
|
||||
"richText-annotator", "reply-annotator", "tags-annotator", "flagging-annotator",
|
||||
"grouping-annotator", "diacritic-annotator", "openseadragon", "jquery-Watch", "catch", "handlebars",
|
||||
"URI"
|
||||
]
|
||||
},
|
||||
"tinymce": {
|
||||
exports: "tinymce"
|
||||
}
|
||||
// End of needed by OVA
|
||||
}
|
||||
});
|
||||
}).call(this, require || RequireJS.require, define || RequireJS.define);
|
||||
@@ -1,167 +0,0 @@
|
||||
;(function (require, define) {
|
||||
var paths = {}, config;
|
||||
|
||||
// jquery, underscore, gettext, URI, tinymce, or jquery.tinymce may already
|
||||
// have been loaded and we do not want to load them a second time. Check if
|
||||
// it is the case and use the global var instead.
|
||||
if (window.jQuery) {
|
||||
define("jquery", [], function() {return window.jQuery;});
|
||||
} else {
|
||||
paths.jquery = "js/vendor/jquery.min";
|
||||
}
|
||||
if (window._) {
|
||||
define("underscore", [], function() {return window._;});
|
||||
} else {
|
||||
paths.jquery = "js/vendor/underscore-min";
|
||||
}
|
||||
if (window.gettext) {
|
||||
define("gettext", [], function() {return window.gettext;});
|
||||
} else {
|
||||
paths.gettext = "/i18n";
|
||||
}
|
||||
if (window.Logger) {
|
||||
define("logger", [], function() {return window.Logger;});
|
||||
} else {
|
||||
paths.logger = "js/src/logger";
|
||||
}
|
||||
if (window.URI) {
|
||||
define("URI", [], function() {return window.URI;});
|
||||
} else {
|
||||
paths.URI = "js/vendor/URI.min";
|
||||
}
|
||||
if (window.tinymce) {
|
||||
define('tinymce', [], function() {return window.tinymce;});
|
||||
} else {
|
||||
paths.tinymce = "js/vendor/tinymce/js/tinymce/tinymce.full.min";
|
||||
}
|
||||
if (window.jquery && window.jquery.tinymce) {
|
||||
define("jquery.tinymce", [], function() {return window.jquery.tinymce;});
|
||||
} else {
|
||||
paths.tinymce = "js/vendor/tinymce/js/tinymce/jquery.tinymce.min";
|
||||
}
|
||||
|
||||
config = {
|
||||
// NOTE: baseUrl has been previously set in lms/static/templates/main.html
|
||||
waitSeconds: 60,
|
||||
paths: {
|
||||
"annotator_1.2.9": "js/vendor/edxnotes/annotator-full.min",
|
||||
"date": "js/vendor/date",
|
||||
"text": 'js/vendor/requirejs/text',
|
||||
"backbone": "js/vendor/backbone-min",
|
||||
"backbone-super": "js/vendor/backbone-super",
|
||||
"backbone.paginator": "js/vendor/backbone.paginator.min",
|
||||
"underscore.string": "js/vendor/underscore.string.min",
|
||||
// Files needed by OVA
|
||||
"annotator": "js/vendor/ova/annotator-full",
|
||||
"annotator-harvardx": "js/vendor/ova/annotator-full-firebase-auth",
|
||||
"video.dev": "js/vendor/ova/video.dev",
|
||||
"vjs.youtube": 'js/vendor/ova/vjs.youtube',
|
||||
"rangeslider": 'js/vendor/ova/rangeslider',
|
||||
"share-annotator": 'js/vendor/ova/share-annotator',
|
||||
"richText-annotator": 'js/vendor/ova/richText-annotator',
|
||||
"reply-annotator": 'js/vendor/ova/reply-annotator',
|
||||
"grouping-annotator": 'js/vendor/ova/grouping-annotator',
|
||||
"tags-annotator": 'js/vendor/ova/tags-annotator',
|
||||
"diacritic-annotator": 'js/vendor/ova/diacritic-annotator',
|
||||
"flagging-annotator": 'js/vendor/ova/flagging-annotator',
|
||||
"jquery-Watch": 'js/vendor/ova/jquery-Watch',
|
||||
"openseadragon": 'js/vendor/ova/openseadragon',
|
||||
"osda": 'js/vendor/ova/OpenSeaDragonAnnotation',
|
||||
"ova": 'js/vendor/ova/ova',
|
||||
"catch": 'js/vendor/ova/catch/js/catch',
|
||||
"handlebars": 'js/vendor/ova/catch/js/handlebars-1.1.2'
|
||||
// end of files needed by OVA
|
||||
},
|
||||
shim: {
|
||||
"annotator_1.2.9": {
|
||||
deps: ["jquery"],
|
||||
exports: "Annotator"
|
||||
},
|
||||
"date": {
|
||||
exports: "Date"
|
||||
},
|
||||
"jquery": {
|
||||
exports: "$"
|
||||
},
|
||||
"underscore": {
|
||||
exports: "_"
|
||||
},
|
||||
"backbone": {
|
||||
deps: ["underscore", "jquery"],
|
||||
exports: "Backbone"
|
||||
},
|
||||
"backbone.paginator": {
|
||||
deps: ["backbone"],
|
||||
exports: "Backbone.Paginator"
|
||||
},
|
||||
"backbone-super": {
|
||||
deps: ["backbone"]
|
||||
},
|
||||
"logger": {
|
||||
exports: "Logger"
|
||||
},
|
||||
// Needed by OVA
|
||||
"video.dev": {
|
||||
exports:"videojs"
|
||||
},
|
||||
"vjs.youtube": {
|
||||
deps: ["video.dev"]
|
||||
},
|
||||
"rangeslider": {
|
||||
deps: ["video.dev"]
|
||||
},
|
||||
"annotator": {
|
||||
exports: "Annotator"
|
||||
},
|
||||
"annotator-harvardx":{
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"share-annotator": {
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"richText-annotator": {
|
||||
deps: ["annotator", "tinymce"]
|
||||
},
|
||||
"reply-annotator": {
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"tags-annotator": {
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"diacritic-annotator": {
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"flagging-annotator": {
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"grouping-annotator": {
|
||||
deps: ["annotator"]
|
||||
},
|
||||
"ova": {
|
||||
exports: "ova",
|
||||
deps: [
|
||||
"annotator", "annotator-harvardx", "video.dev", "vjs.youtube", "rangeslider", "share-annotator",
|
||||
"richText-annotator", "reply-annotator", "tags-annotator", "flagging-annotator",
|
||||
"grouping-annotator", "diacritic-annotator", "jquery-Watch", "catch", "handlebars", "URI"
|
||||
]
|
||||
},
|
||||
"osda": {
|
||||
exports: "osda",
|
||||
deps: [
|
||||
"annotator", "annotator-harvardx", "video.dev", "vjs.youtube", "rangeslider", "share-annotator",
|
||||
"richText-annotator", "reply-annotator", "tags-annotator", "flagging-annotator",
|
||||
"grouping-annotator", "diacritic-annotator", "openseadragon", "jquery-Watch", "catch", "handlebars",
|
||||
"URI"
|
||||
]
|
||||
}
|
||||
// End of needed by OVA
|
||||
}
|
||||
};
|
||||
|
||||
for (var key in paths) {
|
||||
if ({}.hasOwnProperty.call(paths, key)) {
|
||||
config.paths[key] = paths[key];
|
||||
}
|
||||
}
|
||||
require.config(config);
|
||||
}).call(this, require || RequireJS.require, define || RequireJS.define);
|
||||
Reference in New Issue
Block a user