I
I
its2easyy2022-04-13 15:32:57
JavaScript
its2easyy, 2022-04-13 15:32:57

Is it possible to minify the names of public methods of inner classes through Terser?

There are two classes, the first is used in the second, the second is exported.

//file1.js
export default class Foo{
  publicVarFoo = 1;
  #privateVarFoo = 2;
  publicMethodFoo(){}
  #privateMethodFoo(){}
}

//file2.js, entrypoint
import Foo from "./file1.js"

export default class Bar{
  constructor(){
    this.foo = new Foo();
  }
  publicVarBar = 1;
  #privateVarBar = 2;
  publicMethodBar(){
    this.foo.publicMethodFoo();
    console.log(this.foo.publicVarFoo );
  }
  #privateMethodBar(){}
}

The only entry point is the Bar class, the Foo class cannot be obtained from external code. At the same time, terser leaves the names publicVarFoo, publicMethodFoo, publicVarBar, publicMethodBar unchanged, but I would like only public variables and methods of one class that is available to external code, that is, publicVarBar and publicMethodBar .
I found the setting
terserOptions: {
  mangle: {
    properties: {
       regex: /^_/,
    }
  },
 }

but for it you need to rename all variables and functions. Perhaps there is another way?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question