require.amd gets it value from webpackOptions.amd

This commit is contained in:
Tobias Koppers 2012-10-26 10:55:00 +02:00
parent 0908703129
commit e3cb0faac8
6 changed files with 24 additions and 5 deletions

View File

@ -555,6 +555,10 @@ You can also save this options object in a JSON file and use it with the shell c
// default: 0
// only process file in seperate process if more or equal loaders applied to the file.
amd: { jQuery: true },
// default: {}
// specify the value of require.amd and define.amd
profile: true,
// default: false
// capture timings for the build.

View File

@ -12,6 +12,6 @@ function amdRequire(chunk, requiresFn, fn) {
}
for(var name in req)
amdRequire[name] = req[name];
amdRequire.amd = {};
amdRequire.amd = require("./__webpack_options_amd.loader.js!./__webpack_options_amd.loader.js");
amdRequire.config = function() {/* config is ignored, use webpack options */};
module.exports = amdRequire;

View File

@ -0,0 +1,5 @@
module.exports = function() {
this.cacheable();
if(!this.options.amd) return "/* empty to return {} */";
return "module.exports = " + JSON.stringify(this.options.amd);
}

View File

@ -215,8 +215,8 @@ setTimeout(function() {
// cross module system support
window.test(typeof require === "function", "require should be a function");
window.test(typeof define === "function", "define should be a function");
window.test(require.amd, "require.amd should be true");
window.test(define.amd, "define.amd should be true");
window.test(typeof require.amd === "object", "require.amd should be an object");
window.test(typeof define.amd === "object", "define.amd should be an object");
window.test(typeof module === "object", "module should be a object");

View File

@ -11,5 +11,8 @@ module.exports = {
]
}
},
maxChunks: 2
maxChunks: 2,
amd: {
fromOptions: true
}
}

View File

@ -22,4 +22,11 @@ setTimeout(function() {
}, 3000);
window.test(!asnycOk, "Lib2 Chunk 1 should not be loaded yet");
window.test(!asnycOk2, "Lib2 Chunk 2 should not be loaded yet");
exports.ok = true;
exports.ok = true;
var emptyRequire = false;
require([], function() {
emptyRequire = true;
window.test(require.amd.fromOptions, "Lib2 require.amd should come from options");
});
window.test(emptyRequire, "Lib2 empty AMD require should work");