output
umd
output: {libraryTarget: "umd"}
amd
output: {library: "MyLibrary",libraryTarget: "amd"}require(['MyLibrary'], function(MyLibrary) {// 使用 library 做一些事……});// 如果 output.library 未定义,将会生成以下内容。define([], function() {return _entry_return_; // 此模块返回值,是入口 chunk 返回的值});
commonjs2
libraryTarget: "commonjs2"module.exports = _entry_return_;require("MyLibrary").doSomething();
libraryTarget: “common” | “window” | “global” | “this” | “var”
output: {
library: “MyLibrary”,
libraryTarget: “commonjs” | “window” | “global” | “this” | “var”
}
// common.jsexports["MyLibrary"] = _entry_return_;require("MyLibrary").doSomething();// globalglobal["MyLibrary"] = _entry_return_;global.MyLibrary.doSomething();// windowwindow["MyLibrary"] = _entry_return_;window.MyLibrary.doSomething();// thisthis["MyLibrary"] = _entry_return_;// 在一个单独的 script……this.MyLibrary.doSomething();MyLibrary.doSomething(); // 如果 this 是 window// varvar MyLibrary = _entry_return_;// 在一个单独的 script……MyLibrary.doSomething();
