Ionic-app-scripts - tree shaking - removing to much

I have a fairly large TS library that heavily uses decorators. Now for some reason one of the decorators I use gets marked as unused by webpacks tree-shaking.

TypeScript file in question

import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';

@Entity() // this decorator is "unused"
export class User {
  @PrimaryGeneratedColumn() // this decorator is not unused
  user_id_internal: number;
  @Column()
  user_id: string;
  @Column()
  first_name: string;
  @Column()
  last_name: string;
}

which is turned into

var User = (function () {
    function User() {
    }
    return User;
}());
__decorate([
    Object(__WEBPACK_IMPORTED_MODULE_0_typeorm__["d" /* PrimaryGeneratedColumn */])(),
    __metadata("design:type", Number)
], User.prototype, "user_id_internal", void 0);
__decorate([
    Object(__WEBPACK_IMPORTED_MODULE_0_typeorm__["a" /* Column */])(),
    __metadata("design:type", String)
], User.prototype, "user_id", void 0);
__decorate([
    Object(__WEBPACK_IMPORTED_MODULE_0_typeorm__["a" /* Column */])(),
    __metadata("design:type", String)
], User.prototype, "first_name", void 0);
__decorate([
    Object(__WEBPACK_IMPORTED_MODULE_0_typeorm__["a" /* Column */])(),
    __metadata("design:type", String)
], User.prototype, "last_name", void 0);
User = __decorate([
    Object(__WEBPACK_IMPORTED_MODULE_0_typeorm__["b" /* Entity */])()
], User);

After ionic-app-scripts build this comment is added to the Entity decorator: /* unused harmony export Entity */ for the PrimaryGeneratedColumn this comment is added /* harmony export (immutable) */ __webpack_exports__["a"] = PrimaryGeneratedColumn;.

I added

"config": {
   "ionic_purge_decorators": false,
   "ionic_manual_treeshaking": false
}

to package.json but ionic_manual_treeshaking only disables the addional tree shaking.
I know, that this is not an issue of ionic directly and more of webpack. At least I think so. But maybe someone knows a way around this.

Additional information: It seems like webpack or ionic has a problem with the name. When I change to a different decorator AbstractEntity everything is shaken correctly.
Is there a reason for it to not like Entity?

Only thing that comes to mind is that it collides with an interface defined in the DOM.

Thanks for the reply but it turned out, that deep in the library it was exported twice, a mistake the compiler seems to ignore but webpack does not like.

1 Like