typescript-remove-decorators-transformer
v1.0.1
Published
A transformer to use with TypeScript compiler APIs that removes unnecessary decorators. It's particularly useful when sharing code between backend and frontend, preventing backend-specific decorators from appearing in the frontend bundle.
Downloads
5
Maintainers
Readme
TypeScript Transformer Library
Table of Contents
Getting Started
Installation
yarn add typescript-remove-decorators-transformer --dev
or
npm install typescript-remove-decorators-transformer --save-dev
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-remove-decorators-transformer';
const program = ts.createProgram(['./src/main.ts'], {});
const result = program.emit(
undefined,
undefined,
undefined,
false,
{
before: [removeDecoratorsTransformer([
'Column',
'Index',
// decorators to remove
])]
},
);
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-remove-decorators-transformer').default;
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
- https://github.com/itsdouges/typescript-transformer-handbook
- https://github.com/TypeStrong/ts-loader#getcustomtransformers
License
MIT License