如何配置 Webpack 以创建 UMD 包,以便 AMD 和 CommonJS 的包名称将以小写(脊柱大小写)命名,而全局上下文将具有 CamelCase 名称?
例如,我希望我的捆绑包以
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("dependency"));
else if(typeof define === 'function' && define.amd)
define("my-library", ["dependency"], factory); // spinal-case
else if(typeof exports === 'object')
exports["my-library"] = factory(require("dependency")); // spinal-case
else
root["MyLibrary"] = factory(root["dependency"]); // CamelCase
})...
这是它在 ReactDOM 中的样子:
(function(f) {
// CommonJS
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = f(require('react'));
// RequireJS
} else if (typeof define === "function" && define.amd) {
define(['react'], f);
// <script>
} else {
var g;
if (typeof window !== "undefined") {
g = window;
} else if (typeof global !== "undefined") {
g = global;
} else if (typeof self !== "undefined") {
g = self;
} else {
// works providing we're not in "use strict";
// needed for Java 8 Nashorn
// see https://github.com/facebook/react/issues/3037
g = this;
}
g.ReactDOM = f(g.React);
}
})(function(React)...