timocov / ts-transformer-minify-privates

A TypeScript custom transformer which renames private class members
MIT License
52 stars 5 forks source link

How set up with angular? #26

Open cesco69 opened 1 year ago

cesco69 commented 1 year ago

I'm tried:

npm install ts-transformer-minify-privates --save-dev
npm install @angular-builders/custom-webpack  --save-dev
npm install ts-loader  --save-dev

angular.json

  "projects": {
      "architect": {
        "build": {
          "builder": "@angular-builders/custom-webpack:browser",
          "options": {
            "customWebpackConfig": {
              "path": "custom-webpack.config.js",
              "replaceDuplicatePlugins": true
            }
        }
    }
  }

custom-webpack.config.js

// webpack.config.js
var minifyPrivatesTransformer = require('ts-transformer-minify-privates').default;

module.exports = (config, options) => {
  if (config.module && config.module.rules) {
    config.module.rules.push(
      {
        test: /\.ts$/,
        loader: 'ts-loader', // or 'awesome-typescript-loader'
        options: {
          getCustomTransformers: program => ({
            before: [
              minifyPrivatesTransformer(program)
            ]
          })
        }
      }
    );
  }
  return config;
}

tsconfig.ts

"compilerOptions": {
    "plugins": [
      {
        "transform": "ts-transformer-minify-privates"
      }
    ]
}

RUN BUILD

npm run build

but private field aren't minified... :(

timocov commented 1 year ago

Hi @cesco69, I'm not familiar with Angular. Does it give a way to provide custom transformers during the compilation?