admin管理员组

文章数量:1405170

Repro demo link:

Input:

// src/index.ts

import { add } from './math';

(window as any).add = add;
// src/math.ts

export function add(a, b) {
  return a + b;
}

function sealed(constructor) {
  Object.seal(constructor);
  Object.seal(constructor.prototype);
}

/*#__PURE__*/
@sealed
class Foo {
  sub() {
    console.log("hello");
  }
}

In this case, class Foo is not imported or used in index.ts

However, the built result dist/bundle.js has the code console.log("hello")

Is there a way to tree-shake decorator in webpack build?

Related issue:

Vite seems to have a plugin to do this but webpack haven't.

本文标签: javascriptIs there a way to treeshake decorator in webpack buildStack Overflow