Last active
August 29, 2015 14:00
-
-
Save is-already-taken/11346778 to your computer and use it in GitHub Desktop.
main.js with requirejs.config() and NodeJS module export using requirejs Stub and passing the config with assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- r.js 2014-04-27 09:10:55.394219131 +0200 | |
+++ r.js 2014-04-27 16:32:41.574726697 +0200 | |
@@ -23071,9 +23072,16 @@ | |
jsConfig = stringData.value; | |
foundRange = stringData.range; | |
return false; | |
+ } else if (arg && arg.type === "AssignmentExpression") { | |
+ stringData = parse.nodeToString(fileContents, arg.right); | |
+ jsConfig = stringData.value; | |
+ foundRange = stringData.range; | |
+ return false; | |
+ | |
} | |
} else { | |
arg = parse.getRequireObjectLiteral(node); | |
+ | |
if (arg) { | |
stringData = parse.nodeToString(fileContents, arg); | |
jsConfig = stringData.value; | |
@@ -23245,6 +23253,9 @@ | |
// require/requirejs.config({}) call | |
callName = c.object.name + 'Config'; | |
} | |
+ } else if (node && node.type === 'VariableDeclarator' && | |
+ node.id && node.id.name === '_RequireJsConfig') { | |
+ callName = 'requirejsConfigVariable'; | |
} | |
return callName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof requirejs === "undefined") { | |
// Non-browser context: create stub of requirejs API to prevent runtime error | |
var requirejs = { IS_STUB: true }; | |
requirejs.config = function(){ /* STUB*/ }; | |
} | |
var _RequireJSConfig; | |
// Depdending on the context, call the real or stub's config() and | |
// assign config to local variable | |
requirejs.config(_RequireJSConfig = { | |
paths: { | |
// ... | |
}, | |
shim: { | |
// ... | |
} | |
}); | |
if (typeof exports !== "undefined") { | |
// NodeJS context: export assigned config | |
module.exports.requireJsConfig = _RequireJSConfig; | |
} | |
if (!requirejs.IS_STUB) { | |
// Browser context (not subbed): "require" is RequireJS related, not NodeJS | |
require(["jquery", "backbone", "router"], function($, Backbone, Router){ | |
// Code here | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires a patch to r.js making the
findConfig()
method invoked when usingmainConfigFile
aware of inline assignments.