2013-01-31 08:44:39 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
|
|
|
var Module = require("./Module");
|
2015-12-30 00:44:55 +08:00
|
|
|
var RawSource = require("webpack-sources").RawSource;
|
2013-01-31 08:44:39 +08:00
|
|
|
|
|
|
|
function MultiModule(context, dependencies, name) {
|
|
|
|
Module.call(this);
|
|
|
|
this.context = context;
|
|
|
|
this.dependencies = dependencies;
|
|
|
|
this.name = name;
|
|
|
|
this.built = false;
|
|
|
|
this.cacheable = true;
|
|
|
|
}
|
|
|
|
module.exports = MultiModule;
|
|
|
|
|
|
|
|
MultiModule.prototype = Object.create(Module.prototype);
|
2016-05-20 13:39:36 +08:00
|
|
|
MultiModule.prototype.constructor = MultiModule;
|
2013-01-31 08:44:39 +08:00
|
|
|
|
|
|
|
MultiModule.prototype.identifier = function() {
|
2017-01-09 15:31:49 +08:00
|
|
|
return "multi " + this.dependencies.map((d) => d.request).join(" ");
|
2013-01-31 08:44:39 +08:00
|
|
|
};
|
|
|
|
|
2017-01-09 15:31:49 +08:00
|
|
|
MultiModule.prototype.readableIdentifier = function(requestShortener) {
|
|
|
|
return "multi " + this.dependencies.map((d) => {
|
|
|
|
return requestShortener.shorten(d.request);
|
|
|
|
}).join(" ");
|
2013-01-31 08:44:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
MultiModule.prototype.disconnect = function disconnect() {
|
|
|
|
this.built = false;
|
|
|
|
Module.prototype.disconnect.call(this);
|
|
|
|
};
|
|
|
|
|
|
|
|
MultiModule.prototype.build = function build(options, compilation, resolver, fs, callback) {
|
|
|
|
this.built = true;
|
|
|
|
return callback();
|
|
|
|
};
|
|
|
|
|
2015-04-24 05:55:50 +08:00
|
|
|
MultiModule.prototype.source = function(dependencyTemplates, outputOptions) {
|
2013-02-01 17:45:19 +08:00
|
|
|
var str = [];
|
2013-01-31 08:44:39 +08:00
|
|
|
this.dependencies.forEach(function(dep, idx) {
|
2015-07-16 06:19:23 +08:00
|
|
|
if(dep.module) {
|
|
|
|
if(idx === this.dependencies.length - 1)
|
2016-04-22 05:50:28 +08:00
|
|
|
str.push("module.exports = ");
|
2014-03-03 21:56:17 +08:00
|
|
|
str.push("__webpack_require__(");
|
2015-07-16 06:19:23 +08:00
|
|
|
if(outputOptions.pathinfo)
|
2015-04-24 05:55:50 +08:00
|
|
|
str.push("/*! " + dep.request + " */");
|
2015-06-28 04:47:51 +08:00
|
|
|
str.push("" + JSON.stringify(dep.module.id));
|
2013-01-31 08:44:39 +08:00
|
|
|
str.push(")");
|
|
|
|
} else {
|
|
|
|
str.push("(function webpackMissingModule() { throw new Error(");
|
|
|
|
str.push(JSON.stringify("Cannot find module \"" + dep.request + "\""));
|
|
|
|
str.push("); }())");
|
|
|
|
}
|
|
|
|
str.push(";\n");
|
2013-02-01 17:45:19 +08:00
|
|
|
}, this);
|
2013-01-31 08:44:39 +08:00
|
|
|
return new RawSource(str.join(""));
|
|
|
|
};
|
|
|
|
|
2015-04-24 05:55:50 +08:00
|
|
|
MultiModule.prototype.needRebuild = function needRebuild() {
|
2013-01-31 08:44:39 +08:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
MultiModule.prototype.size = function() {
|
|
|
|
return 16 + this.dependencies.length * 12;
|
|
|
|
};
|
|
|
|
|
|
|
|
MultiModule.prototype.updateHash = function(hash) {
|
|
|
|
hash.update("multi module");
|
|
|
|
hash.update(this.name || "");
|
|
|
|
Module.prototype.updateHash.call(this, hash);
|
|
|
|
};
|