Terser mangle props accessed by string vars

98 views Asked by At

Is there a way to change the mangled key from string vars or prevent mangling the prop if accessed by var?

Ex:

# webpack.js
new TerserPlugin({
  parallel: false,
  terserOptions: {
    nameCache: mangleLegend,
    mangle: {
      properties: {
        regex: /^manglePrefix_/,
        keep_quoted: true,
      },
    },
  },
}),


# test.js
const someObject = {
  manglePrefix_name: 'Some name',
}

const key = 'manglePrefix_name';

console.log(someObject[key]); // either also mangle the string or prevent mangling the object altogether
console.log(someObject.hasOwnProperty(key)); // this is nice to have, but not mandatory.

I know that if I use the string directly in brackets it will work/ignore based on keep_quoted, but I'm interested in the case with the variable/enum (TypeScript)

0

There are 0 answers