Skip to content

Template project for TypeScript's custom transformer

License

Notifications You must be signed in to change notification settings

timocov/ts-transformer-template

Repository files navigation

ts-transformer-transformerName

GH Actions npm version Downloads

Installation

  1. Install the package npm i -D ts-transformer-transformerName
  2. Add transformer with one of possible ways

Options

How to use the custom transformer

Unfortunately, TypeScript itself does not currently provide any easy way to use custom transformers (see microsoft/TypeScript#14419). The followings are the example usage of the custom transformer.

webpack (with ts-loader or awesome-typescript-loader)

// webpack.config.js
const transformerName = require('ts-transformer-transformerName').default;

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: 'ts-loader', // or 'awesome-typescript-loader'
        options: {
          getCustomTransformers: program => ({
              before: [
                  transformerName(program, { entrySourceFiles: ['./src/index.ts'] })
              ]
          })
        }
      }
    ]
  }
};

Rollup (with rollup-plugin-typescript2)

// rollup.config.js
import typescript from 'rollup-plugin-typescript2';
import transformerName from 'ts-transformer-transformerName';

export default {
  // ...
  plugins: [
    typescript({ transformers: [service => ({
      before: [ transformerName(service.getProgram(), { entrySourceFiles: ['./src/index.ts'] }) ],
      after: []
    })] })
  ]
};

ttypescript

See ttypescript's README for how to use this with module bundlers such as webpack or Rollup.

tsconfig.json:

{
  "compilerOptions": {
    // ...
    "plugins": [
      { "transform": "ts-transformer-transformerName", "entrySourceFiles": ["./src/index.ts"] }
    ]
  },
  // ...
}

About

Template project for TypeScript's custom transformer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages