0.1.1 • Published 2 years ago

@tybys/ts-transform-pure-class v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

ts-transform-pure-class

Replace /** @class */ to /*#__PURE__*/ in ES5 class output for better tree shaking.

Input:

class C {}

Output:

var C = /*#__PURE__*/ (function () {
    function C() {
    }
    return C;
}());

Usage

npm install -D @tybys/ts-transform-pure-class
{
  "compilerOptions": {
    "removeComments": false,
    "target": "ES5",
    "plugins": [
      {
        "transform": "@tybys/ts-transform-pure-class",
        "type": "raw",
        "after": true
      }
    ]
  }
}
{
  "compilerOptions": {
    "removeComments": false,
    "target": "ES5"
  }
}
// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: [
          {
            loader: 'ts-loader',
            options: {
              getCustomTransformers () {
                return {
                  after: [require('@tybys/ts-transform-pure-class').default]
                }
              }
            }
          }
        ]
      }
    ]
  }
}
{
  "compilerOptions": {
    "removeComments": false,
    "target": "ES5",
    "module": "ESNext"
  }
}
// rollup.config.js
import { join } from 'path'
import typescript from '@rollup/plugin-typescript'

export default {
  plugins: [
    typescript({
      transformers: {
        after: [require('@tybys/ts-transform-pure-class').default]
      }
    })
  ]
}