我正在尝试使用 google 闭包编译一个相对复杂的 angular5 项目。
首先我使用tsickle将代码编译成对 google 闭包友好的语法,然后我尝试使用 google 闭包来创建最终包。
不幸的是,tsickle 似乎创建了一个与 google 闭包不兼容的模块格式,对于我拥有的所有模块,我都收到以下错误:
./path/to/my.component.js:8: ERROR - The body of a goog.module cannot reference this.
var __metadata = (this && this.__metadata) || function (k, v) {
但是,考虑到最近 ngc -> tsickle 使用 angular5 切换以帮助构建闭包的意图,我认为它应该可以工作。
检查一点 my path/to/component.js
,我在一开始就发现了这个:
goog.module('target.path.to.MyComponent');var module = module || {id: 'target/path/to/MyComponent.js'};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
看来,打字稿编译器(由 tsickle 内部调用)将此代码放在所有模块之前,它在 tsickle 不知情的情况下执行此操作,并且使模块格式与 google 闭包不兼容!
该怎么办?如何解决它?