Skip to content

Instantly share code, notes, and snippets.

@sylvinus
Created December 14, 2011 19:20
Show Gist options
  • Save sylvinus/1478040 to your computer and use it in GitHub Desktop.
Save sylvinus/1478040 to your computer and use it in GitHub Desktop.
var requirejs = require("requirejs");
requirejs.config({
nodeRequire: require,
baseUrl: "./"
});
requirejs(["./app/path2"],function(p2) {
console.warn("ok1");
});
var config = {
baseUrl: "./app/",
name: "./start",
out: "out.js"
};
requirejs.optimize(config, function (buildResponse) {
console.warn("success!");
requirejs.config({
nodeRequire: require,
baseUrl: "./"
});
requirejs(["./app/path2"],function(p2) {
console.warn("I should be shown!");
});
});
@jrburke
Copy link

jrburke commented Dec 14, 2011

This may not work:

//For the non-optimize() calls, use the context: config to create a new context for the code to run in, 
//that is separate from the default context used by requirejs for builds. And then, since the build 
//overrides are in effect, a special flag needs to be added to the callback function to tell requirejs 
//to just execute it:

var appRequire = requirejs.config({
    nodeRequire: require,
    baseUrl: "./"
    context: 'appRequire'
});

function appCallback(p2) {
    console.warn("I should be shown!");
}
appCallback.__requireJsBuild = true;

appRequire((["./app/path2"], appCallback);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment