1.0.6 • Published 2 years ago

typescript-transformer-remove-decorators v1.0.6

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

TypeScript Transformer Library

This library provides a set of TypeScript transformers that can be used to modify or enhance your TypeScript code during the compilation process. Transformers are a powerful tool that allow you to inspect and change your code directly from within the TypeScript compiler.

Purpose

The main purpose of this library is to provide a set of transformers that can be used to remove unnecessary decorators from your TypeScript code. This is particularly useful when sharing code between the backend and frontend, as it allows you to prevent backend-specific decorators from appearing in the frontend bundle.

Installation

You can install this library using npm. Run the following command in your terminal:

npm install typescript-transformer-library

Usage with TypeScript Transformers

To use a transformer from this library, you need to pass it to the TypeScript compiler during the compilation process. This can be done by using the customTransformers option of the TypeScript compiler API.

Here is an example of how to use a transformer:

import { removeDecoratorsTransformer } from 'typescript-transformer-remove-decorator';

const program = ts.createProgram(['./src/main.ts'], {});

const result = program.emit(undefined, undefined, undefined, false, {
  before: [removeDecoratorsTransformer(program)]
});

Usage with ts-loader

If you are using ts-loader, you can use the getCustomTransformers option to provide your custom transformers. Here is an example:

// webpack.config.js
const { removeDecoratorsTransformer } = require('typescript-transformer-remove-decorator');

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: 'ts-loader',
        options: {
          getCustomTransformers: program => ({
            before: [removeDecoratorsTransformer([
                'Column',
                // decorators to remove
            ])]
          })
        }
      }
    ]
  }
};

In this example, the removeDecoratorsTransformer is used to remove all decorators from the TypeScript code during the webpack build process.

References

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago