aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/UmdMainTemplatePlugin.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/webpack/lib/UmdMainTemplatePlugin.js
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
node_modules
Diffstat (limited to 'node_modules/webpack/lib/UmdMainTemplatePlugin.js')
-rw-r--r--node_modules/webpack/lib/UmdMainTemplatePlugin.js49
1 files changed, 32 insertions, 17 deletions
diff --git a/node_modules/webpack/lib/UmdMainTemplatePlugin.js b/node_modules/webpack/lib/UmdMainTemplatePlugin.js
index 81873305a..3ddb98d23 100644
--- a/node_modules/webpack/lib/UmdMainTemplatePlugin.js
+++ b/node_modules/webpack/lib/UmdMainTemplatePlugin.js
@@ -23,7 +23,17 @@ function accessorAccess(base, accessor) {
class UmdMainTemplatePlugin {
constructor(name, options) {
- this.name = name;
+ if(typeof name === "object" && !Array.isArray(name)) {
+ this.name = name.root || name.amd || name.commonjs;
+ this.names = name;
+ } else {
+ this.name = name;
+ this.names = {
+ commonjs: name,
+ root: name,
+ amd: name
+ };
+ }
this.optionalAmdExternalAsGlobal = options.optionalAmdExternalAsGlobal;
this.namedDefine = options.namedDefine;
this.auxiliaryComment = options.auxiliaryComment;
@@ -31,8 +41,8 @@ class UmdMainTemplatePlugin {
apply(compilation) {
const mainTemplate = compilation.mainTemplate;
- compilation.templatesPlugin("render-with-entry", function(source, chunk, hash) {
- let externals = chunk.modules.filter(m => m.external);
+ compilation.templatesPlugin("render-with-entry", (source, chunk, hash) => {
+ let externals = chunk.getModules().filter(m => m.external);
const optionalExternals = [];
let requiredExternals = [];
if(this.optionalAmdExternalAsGlobal) {
@@ -72,6 +82,7 @@ class UmdMainTemplatePlugin {
let expr;
let request = m.request;
if(typeof request === "object") request = request[type];
+ if(typeof request === "undefined") throw new Error("Missing external configuration for type:" + type);
if(Array.isArray(request)) {
expr = `require(${JSON.stringify(request[0])})${accessorToObjectAccess(request.slice(1))}`;
} else
@@ -124,16 +135,16 @@ class UmdMainTemplatePlugin {
) +
" else if(typeof define === 'function' && define.amd)\n" +
(requiredExternals.length > 0 ?
- (this.name && this.namedDefine === true ?
- " define(" + libraryName(this.name) + ", " + externalsDepsArray(requiredExternals) + ", " + amdFactory + ");\n" :
+ (this.names.amd && this.namedDefine === true ?
+ " define(" + libraryName(this.names.amd) + ", " + externalsDepsArray(requiredExternals) + ", " + amdFactory + ");\n" :
" define(" + externalsDepsArray(requiredExternals) + ", " + amdFactory + ");\n"
) :
- (this.name && this.namedDefine === true ?
- " define(" + libraryName(this.name) + ", [], " + amdFactory + ");\n" :
+ (this.names.amd && this.namedDefine === true ?
+ " define(" + libraryName(this.names.amd) + ", [], " + amdFactory + ");\n" :
" define([], " + amdFactory + ");\n"
)
) +
- (this.name ?
+ (this.names.root || this.names.commonjs ?
(this.auxiliaryComment &&
typeof this.auxiliaryComment === "string" ?
" //" + this.auxiliaryComment + "\n" :
@@ -142,7 +153,7 @@ class UmdMainTemplatePlugin {
""
) +
" else if(typeof exports === 'object')\n" +
- " exports[" + libraryName(this.name) + "] = factory(" + externalsRequireArray("commonjs") + ");\n" +
+ " exports[" + libraryName(this.names.commonjs || this.names.root) + "] = factory(" + externalsRequireArray("commonjs") + ");\n" +
(this.auxiliaryComment &&
typeof this.auxiliaryComment === "string" ?
" //" + this.auxiliaryComment + "\n" :
@@ -151,7 +162,7 @@ class UmdMainTemplatePlugin {
""
) +
" else\n" +
- " " + replaceKeys(accessorAccess("root", this.name)) + " = factory(" + externalsRootArray(externals) + ");\n" :
+ " " + replaceKeys(accessorAccess("root", this.names.root || this.names.commonjs)) + " = factory(" + externalsRootArray(externals) + ");\n" :
" else {\n" +
(externals.length > 0 ?
" var a = typeof exports === 'object' ? factory(" + externalsRequireArray("commonjs") + ") : factory(" + externalsRootArray(externals) + ");\n" :
@@ -161,15 +172,19 @@ class UmdMainTemplatePlugin {
" }\n"
) +
"})(this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})");
- }.bind(this));
- mainTemplate.plugin("global-hash-paths", function(paths) {
- if(this.name) paths = paths.concat(this.name);
+ });
+ mainTemplate.plugin("global-hash-paths", (paths) => {
+ if(this.names.root) paths = paths.concat(this.names.root);
+ if(this.names.amd) paths = paths.concat(this.names.amd);
+ if(this.names.commonjs) paths = paths.concat(this.names.commonjs);
return paths;
- }.bind(this));
- mainTemplate.plugin("hash", function(hash) {
+ });
+ mainTemplate.plugin("hash", (hash) => {
hash.update("umd");
- hash.update(`${this.name}`);
- }.bind(this));
+ hash.update(`${this.names.root}`);
+ hash.update(`${this.names.amd}`);
+ hash.update(`${this.names.commonjs}`);
+ });
}
}