【发布时间】:2016-08-02 02:12:25
【问题描述】:
我在 TypeScript 的帮助下编写项目。项目分为许多模块。 我使用 Webpack 将所有模块捆绑到一个文件中。
对于每个从父类扩展的模块类,webpack 添加了 TypeScript __extends 助手。
结果 - 我得到了很多重复的代码。
/***/ },
/* 24 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var DeepExtend_1 = __webpack_require__(6);
//...
exports.SafariDetector = SafariDetector;
/***/ },
/* 25 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var DeepExtend_1 = __webpack_require__(6);
//...
exports.SafariMobileDetector = SafariMobileDetector;
那么,有什么办法可以解决这个问题?
【问题讨论】:
-
这是 TypeScript 编译器在检测到“extends”关键字时的默认行为。由于编译器不知道您是否要将输出捆绑到一个或多个文件中,因此无论关键字在哪里,它都会发出 sn-p。
-
谷歌搜索后我发现
--noEmitHelpers标志,它禁用助手。但现在我需要手动将所有 TS 助手包含在 Webpack npmjs.com/package/typescript-helpers 中。我现在在家,但明天我会尝试使用imports-loaderwebpack.github.io/docs/shimming-modules.html#importing 或其他方式。
标签: typescript webpack