Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: templates/modules.js.tmpl

Issue 29399569: Issue 5060 - Move require into modules template, make info a module (Closed)
Patch Set: Don't redeclare require Created March 31, 2017, 6:48 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: templates/modules.js.tmpl
diff --git a/templates/modules.js.tmpl b/templates/modules.js.tmpl
index c826d892704589d344ecb9fadb61348ab8448b3b..ace95f66133767c516ae0e2218ce3f565e9c7348 100644
--- a/templates/modules.js.tmpl
+++ b/templates/modules.js.tmpl
@@ -1,4 +1,18 @@
{%- if args["module"] -%}
+if (!("require" in window))
Sebastian Noack 2017/03/31 10:42:01 The assumption of the global object being "window"
kzar 2017/03/31 14:03:01 Done.
+{
+ window.require = function(module)
+ {
+ if (!(module in require.scopes))
+ {
+ let scope = {exports: {}};
+ require.scopes[module] = require.modules[module](scope, scope.exports);
+ }
+ return require.scopes[module];
+ }
+ require.modules = Object.create(null);
+ require.scopes = Object.create(null);
+}
{%- for module_name, script in modules -%}
require.modules[{{ module_name|json }}] = function(module, exports)
{

Powered by Google App Engine
This is Rietveld