rollup-plugin-ts-treeshaking

raw JSON →
1.0.2 verified Mon Apr 27 auth: no javascript

Rollup plugin that improves TypeScript tree-shaking by replacing `/** @class */` annotations (generated by TypeScript) with `/*@__PURE__*/` comments, enabling UglifyJS/Terser dead code elimination. Version 1.0.2, minimal release cadence. Differentiator: simple transformation approach vs. full AST manipulation.

error Error: The 'rollup-plugin-ts-treeshaking' plugin is not compatible with Rollup 0.x
cause Plugin requires Rollup 1.x or higher due to plugin API changes.
fix
Upgrade Rollup to version 1.0.0 or higher (npm install rollup@latest).
error TypeError: tsTreeshaking is not a function
cause Using named import instead of default import.
fix
Use default import: import tsTreeshaking from 'rollup-plugin-ts-treeshaking'
error Cannot find module 'rollup-plugin-ts-treeshaking' or its corresponding type declarations.
cause Missing @types/rollup-plugin-ts-treeshaking or TypeScript not resolving types.
fix
Install the package normally; it ships its own types. Ensure tsconfig.json includes 'types': ['rollup-plugin-ts-treeshaking'] or uses node module resolution.
breaking Requires Rollup 1.x or higher; not compatible with Rollup 0.x.
fix Upgrade Rollup to version 1.0.0 or higher.
deprecated rollup-plugin-typescript2 is unmaintained; consider alternatives.
gotcha Only works if minify plugin (UglifyJS or Terser) runs AFTER this plugin in the Rollup build pipeline.
fix Ensure tsTreeshaking() appears before minify plugin in the plugins array.
gotcha Plugin transforms all .ts and .tsx files by default; set `js: true` option to also process .js/.jsx.
gotcha May not work with TypeScript 4+ if class annotations are emitted differently.
gotcha Does not handle async functions or other patterns that generate `@class` annotations.
npm install rollup-plugin-ts-treeshaking
yarn add rollup-plugin-ts-treeshaking
pnpm add rollup-plugin-ts-treeshaking

Configure Rollup with typescript2 plugin and ts-treeshaking to enable Terser dead code elimination via @__PURE__ annotations.

import typescript from 'rollup-plugin-typescript2';
import tsTreeshaking from 'rollup-plugin-ts-treeshaking';

export default {
  input: 'src/index.ts',
  output: {
    file: 'dist/bundle.js',
    format: 'iife',
  },
  plugins: [
    typescript({ useTsconfigDeclarationDir: true }),
    tsTreeshaking(),
  ],
};