From de98e0b232509d5f40c135d540a70e415272ff85 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 3 May 2017 15:35:00 +0200 Subject: node_modules --- node_modules/webpack/lib/LibraryTemplatePlugin.js | 87 +++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 node_modules/webpack/lib/LibraryTemplatePlugin.js (limited to 'node_modules/webpack/lib/LibraryTemplatePlugin.js') diff --git a/node_modules/webpack/lib/LibraryTemplatePlugin.js b/node_modules/webpack/lib/LibraryTemplatePlugin.js new file mode 100644 index 000000000..6e389053d --- /dev/null +++ b/node_modules/webpack/lib/LibraryTemplatePlugin.js @@ -0,0 +1,87 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +const SetVarMainTemplatePlugin = require("./SetVarMainTemplatePlugin"); + +function accessorToObjectAccess(accessor) { + return accessor.map((a) => { + return `[${JSON.stringify(a)}]`; + }).join(""); +} + +function accessorAccess(base, accessor, joinWith) { + accessor = [].concat(accessor); + return accessor.map((a, idx) => { + a = base ? + base + accessorToObjectAccess(accessor.slice(0, idx + 1)) : + accessor[0] + accessorToObjectAccess(accessor.slice(1, idx + 1)); + if(idx === accessor.length - 1) return a; + if(idx === 0 && typeof base === "undefined") return `${a} = typeof ${a} === "object" ? ${a} : {}`; + return `${a} = ${a} || {}`; + }).join(joinWith || "; "); +} + +class LibraryTemplatePlugin { + + constructor(name, target, umdNamedDefine, auxiliaryComment) { + this.name = name; + this.target = target; + this.umdNamedDefine = umdNamedDefine; + this.auxiliaryComment = auxiliaryComment; + } + + apply(compiler) { + compiler.plugin("this-compilation", (compilation) => { + switch(this.target) { + case "var": + compilation.apply(new SetVarMainTemplatePlugin(`var ${accessorAccess(false, this.name)}`)); + break; + case "assign": + compilation.apply(new SetVarMainTemplatePlugin(accessorAccess(undefined, this.name))); + break; + case "this": + case "window": + case "global": + if(this.name) + compilation.apply(new SetVarMainTemplatePlugin(accessorAccess(this.target, this.name))); + else + compilation.apply(new SetVarMainTemplatePlugin(this.target, true)); + break; + case "commonjs": + if(this.name) + compilation.apply(new SetVarMainTemplatePlugin(accessorAccess("exports", this.name))); + else + compilation.apply(new SetVarMainTemplatePlugin("exports", true)); + break; + case "commonjs2": + case "commonjs-module": + compilation.apply(new SetVarMainTemplatePlugin("module.exports")); + break; + case "amd": + var AmdMainTemplatePlugin = require("./AmdMainTemplatePlugin"); + compilation.apply(new AmdMainTemplatePlugin(this.name)); + break; + case "umd": + case "umd2": + var UmdMainTemplatePlugin = require("./UmdMainTemplatePlugin"); + compilation.apply(new UmdMainTemplatePlugin(this.name, { + optionalAmdExternalAsGlobal: this.target === "umd2", + namedDefine: this.umdNamedDefine, + auxiliaryComment: this.auxiliaryComment + })); + break; + case "jsonp": + var JsonpExportMainTemplatePlugin = require("./JsonpExportMainTemplatePlugin"); + compilation.apply(new JsonpExportMainTemplatePlugin(this.name)); + break; + default: + throw new Error(`${this.target} is not a valid Library target`); + } + }); + } +} + +module.exports = LibraryTemplatePlugin; -- cgit v1.2.3