2013-01-31 08:44:39 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2017-03-10 19:19:33 +08:00
|
|
|
"use strict";
|
2013-01-31 08:44:39 +08:00
|
|
|
|
2018-07-30 23:08:51 +08:00
|
|
|
const { RawSource } = require("webpack-sources");
|
2017-03-10 19:19:33 +08:00
|
|
|
const Module = require("./Module");
|
2017-08-02 21:39:43 +08:00
|
|
|
const Template = require("./Template");
|
2017-03-10 19:19:33 +08:00
|
|
|
|
2018-07-30 23:08:51 +08:00
|
|
|
/** @typedef {import("webpack-sources").Source} Source */
|
2018-07-25 18:12:17 +08:00
|
|
|
/** @typedef {import("./Compilation")} Compilation */
|
|
|
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
2018-07-30 23:08:51 +08:00
|
|
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
2018-07-25 18:12:17 +08:00
|
|
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
2018-07-30 23:08:51 +08:00
|
|
|
/** @typedef {import("./util/createHash").Hash} Hash */
|
2018-07-21 00:17:51 +08:00
|
|
|
|
2017-03-10 19:19:33 +08:00
|
|
|
class MultiModule extends Module {
|
|
|
|
constructor(context, dependencies, name) {
|
2018-01-31 04:40:44 +08:00
|
|
|
super("javascript/dynamic", context);
|
2017-11-06 20:02:35 +08:00
|
|
|
|
|
|
|
// Info from Factory
|
2017-03-10 19:19:33 +08:00
|
|
|
this.dependencies = dependencies;
|
|
|
|
this.name = name;
|
2018-03-13 08:17:49 +08:00
|
|
|
this._identifier = `multi ${this.dependencies
|
|
|
|
.map(d => d.request)
|
|
|
|
.join(" ")}`;
|
2017-03-10 19:19:33 +08:00
|
|
|
}
|
2013-01-31 08:44:39 +08:00
|
|
|
|
2018-07-25 18:12:17 +08:00
|
|
|
/**
|
|
|
|
* @returns {string} a unique identifier of the module
|
|
|
|
*/
|
2017-03-10 19:19:33 +08:00
|
|
|
identifier() {
|
2018-03-13 08:17:49 +08:00
|
|
|
return this._identifier;
|
2017-03-10 19:19:33 +08:00
|
|
|
}
|
2013-01-31 08:44:39 +08:00
|
|
|
|
2018-07-25 18:12:17 +08:00
|
|
|
/**
|
|
|
|
* @param {RequestShortener} requestShortener the request shortener
|
|
|
|
* @returns {string} a user readable identifier of the module
|
|
|
|
*/
|
2017-03-10 19:19:33 +08:00
|
|
|
readableIdentifier(requestShortener) {
|
2018-02-25 09:00:20 +08:00
|
|
|
return `multi ${this.dependencies
|
|
|
|
.map(d => requestShortener.shorten(d.request))
|
|
|
|
.join(" ")}`;
|
2017-03-10 19:19:33 +08:00
|
|
|
}
|
2013-01-31 08:44:39 +08:00
|
|
|
|
2018-07-25 18:12:17 +08:00
|
|
|
/**
|
|
|
|
* @param {TODO} options TODO
|
|
|
|
* @param {Compilation} compilation the compilation
|
|
|
|
* @param {TODO} resolver TODO
|
|
|
|
* @param {TODO} fs the file system
|
|
|
|
* @param {function(Error=): void} callback callback function
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-03-10 19:19:33 +08:00
|
|
|
build(options, compilation, resolver, fs, callback) {
|
|
|
|
this.built = true;
|
2017-12-06 19:09:17 +08:00
|
|
|
this.buildMeta = {};
|
|
|
|
this.buildInfo = {};
|
2017-03-10 19:19:33 +08:00
|
|
|
return callback();
|
|
|
|
}
|
2013-01-31 08:44:39 +08:00
|
|
|
|
2018-07-25 18:38:34 +08:00
|
|
|
/**
|
|
|
|
* @param {TODO} fileTimestamps timestamps of files
|
|
|
|
* @param {TODO} contextTimestamps timestamps of directories
|
|
|
|
* @returns {boolean} true, if the module needs a rebuild
|
|
|
|
*/
|
|
|
|
needRebuild(fileTimestamps, contextTimestamps) {
|
2017-03-10 19:19:33 +08:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-31 08:44:39 +08:00
|
|
|
|
2018-07-25 18:12:17 +08:00
|
|
|
/**
|
|
|
|
* @returns {number} the estimated size of the module
|
|
|
|
*/
|
2017-03-10 19:19:33 +08:00
|
|
|
size() {
|
|
|
|
return 16 + this.dependencies.length * 12;
|
|
|
|
}
|
2013-01-31 08:44:39 +08:00
|
|
|
|
2018-07-21 00:17:51 +08:00
|
|
|
/**
|
|
|
|
* @param {Hash} hash the hash used to track dependencies
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-03-10 19:19:33 +08:00
|
|
|
updateHash(hash) {
|
|
|
|
hash.update("multi module");
|
|
|
|
hash.update(this.name || "");
|
|
|
|
super.updateHash(hash);
|
|
|
|
}
|
2013-01-31 08:44:39 +08:00
|
|
|
|
2018-07-25 18:12:17 +08:00
|
|
|
/**
|
|
|
|
* @param {DependencyTemplates} dependencyTemplates the dependency templates
|
|
|
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
|
|
* @param {string=} type the type of source that should be returned
|
|
|
|
* @returns {Source} generated source
|
|
|
|
*/
|
|
|
|
source(dependencyTemplates, runtimeTemplate, type) {
|
2017-03-10 19:19:33 +08:00
|
|
|
const str = [];
|
2018-01-22 20:52:43 +08:00
|
|
|
let idx = 0;
|
2018-02-25 09:00:20 +08:00
|
|
|
for (const dep of this.dependencies) {
|
|
|
|
if (dep.module) {
|
2018-05-29 20:50:40 +08:00
|
|
|
if (idx === this.dependencies.length - 1) {
|
|
|
|
str.push("module.exports = ");
|
|
|
|
}
|
2017-03-10 19:19:33 +08:00
|
|
|
str.push("__webpack_require__(");
|
2018-05-29 20:50:40 +08:00
|
|
|
if (runtimeTemplate.outputOptions.pathinfo) {
|
2017-08-02 21:39:43 +08:00
|
|
|
str.push(Template.toComment(dep.request));
|
2018-05-29 20:50:40 +08:00
|
|
|
}
|
2017-03-10 19:19:33 +08:00
|
|
|
str.push(`${JSON.stringify(dep.module.id)}`);
|
|
|
|
str.push(")");
|
|
|
|
} else {
|
2018-02-25 09:00:20 +08:00
|
|
|
const content = require("./dependencies/WebpackMissingModule").module(
|
|
|
|
dep.request
|
|
|
|
);
|
2017-12-19 22:31:43 +08:00
|
|
|
str.push(content);
|
2017-03-10 19:19:33 +08:00
|
|
|
}
|
|
|
|
str.push(";\n");
|
2018-01-22 20:52:43 +08:00
|
|
|
idx++;
|
|
|
|
}
|
2017-03-10 19:19:33 +08:00
|
|
|
return new RawSource(str.join(""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = MultiModule;
|