2017-05-03 15:35:00 +02:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const ConcatSource = require("webpack-sources").ConcatSource;
|
|
|
|
|
|
|
|
class FunctionModuleTemplatePlugin {
|
|
|
|
apply(moduleTemplate) {
|
|
|
|
moduleTemplate.plugin("render", function(moduleSource, module) {
|
|
|
|
const source = new ConcatSource();
|
|
|
|
const defaultArguments = [module.moduleArgument || "module", module.exportsArgument || "exports"];
|
|
|
|
if((module.arguments && module.arguments.length !== 0) || module.hasDependencies(d => d.requireWebpackRequire !== false)) {
|
|
|
|
defaultArguments.push("__webpack_require__");
|
|
|
|
}
|
|
|
|
source.add("/***/ (function(" + defaultArguments.concat(module.arguments || []).join(", ") + ") {\n\n");
|
|
|
|
if(module.strict) source.add("\"use strict\";\n");
|
|
|
|
source.add(moduleSource);
|
|
|
|
source.add("\n\n/***/ })");
|
|
|
|
return source;
|
|
|
|
});
|
|
|
|
|
|
|
|
moduleTemplate.plugin("package", function(moduleSource, module) {
|
|
|
|
if(this.outputOptions.pathinfo) {
|
|
|
|
const source = new ConcatSource();
|
|
|
|
const req = module.readableIdentifier(this.requestShortener);
|
2017-08-14 05:01:11 +02:00
|
|
|
source.add("/*!****" + req.replace(/./g, "*") + "****!*\\\n");
|
|
|
|
source.add(" !*** " + req.replace(/\*\//g, "*_/") + " ***!\n");
|
|
|
|
source.add(" \\****" + req.replace(/./g, "*") + "****/\n");
|
2017-05-03 15:35:00 +02:00
|
|
|
if(Array.isArray(module.providedExports))
|
2017-08-14 05:01:11 +02:00
|
|
|
source.add("/*! exports provided: " + module.providedExports.join(", ") + " */\n");
|
2017-05-03 15:35:00 +02:00
|
|
|
else if(module.providedExports)
|
2017-08-14 05:01:11 +02:00
|
|
|
source.add("/*! no static exports found */\n");
|
2017-05-03 15:35:00 +02:00
|
|
|
if(Array.isArray(module.usedExports))
|
2017-08-14 05:01:11 +02:00
|
|
|
source.add("/*! exports used: " + module.usedExports.join(", ") + " */\n");
|
2017-05-03 15:35:00 +02:00
|
|
|
else if(module.usedExports)
|
2017-08-14 05:01:11 +02:00
|
|
|
source.add("/*! all exports used */\n");
|
|
|
|
if(module.optimizationBailout) {
|
|
|
|
module.optimizationBailout.forEach(text => {
|
|
|
|
if(typeof text === "function") text = text(this.requestShortener);
|
|
|
|
source.add(`/*! ${text} */\n`);
|
|
|
|
});
|
|
|
|
}
|
2017-05-03 15:35:00 +02:00
|
|
|
source.add(moduleSource);
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
return moduleSource;
|
|
|
|
});
|
|
|
|
|
|
|
|
moduleTemplate.plugin("hash", function(hash) {
|
|
|
|
hash.update("FunctionModuleTemplatePlugin");
|
|
|
|
hash.update("2");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = FunctionModuleTemplatePlugin;
|