@tybys/ts-transform-pure-class
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

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
ttypescript
{
  "compilerOptions": {
    "removeComments": false,
    "target": "ES5",
    "plugins": [
      {
        "transform": "@tybys/ts-transform-pure-class",
        "type": "raw",
        "after": true
      }
    ]
  }
}

webpack
{
  "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]
                }
              }
            }
          }
        ]
      }
    ]
  }
}

rollup
{
  "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]
      }
    })
  ]
}

Readme

Keywords

none

Package Sidebar

Install

npm i @tybys/ts-transform-pure-class

Weekly Downloads

47

Version

0.1.1

License

MIT

Unpacked Size

3.87 kB

Total Files

5

Last publish

Collaborators

  • toyobayashi