我正在研究与应用程序一起使用的打字稿模块,当我将tsconfig更改为将umd
类型使用module
时,这是生成的代码:
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object")
{
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "./test"], factory);
}
})(function (require, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
var test = require("./test").test;
exports.default = test;
}
但是,在我打包所有内容后,我得到了webpackMissingModule
我对其进行了跟踪,发现使用require
只是一个函数被替换为
!(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }())
所以我上面的代码变成了
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(!(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()), exports);
if (v !== undefined) module.exports = v;
}
else if (true) {
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(127), __webpack_require__(198), __webpack_require__(199), __webpack_require__(433)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
__WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
(__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
}
})(function (require, exports) {
...
我对webpack非常陌生,只是最近才开始使用打字稿编写模块,因此将不胜感激!