preserve json object used as dictionary with terser

I currently bundle my typescript code with rollup and want to use terser for minifying/uglifying. In my code I have a dictionary object and imported it into my typescript code.

const dict = { ironResource : "Iron" }

In my code I use it to translate identifiers to other languages or access configs by item identifiers (ironResource). Terser will mangle my keys and destroys the purpose of the object.

const B1 = { aB1 : "Iron" }

Terser settings:

terser({
        parse: {
        },
        compress: {
        },
        mangle: {

            properties: {

            }
        },
        format: {
        },
        ecma: 5,
        keep_classnames: false,
        keep_fnames: false,
        ie8: false,
        module: false,
        nameCache: null,
        safari10: false,
        toplevel: false,
    })

How to stop terser from doing this?

1 answer

  • answered 2020-10-23 12:25 H.B.

    I would expect that you need to set mangle like this:

    mangle: {
        properties: false
    },
    

    Or set the correct options in the properties option object to keep those in particular. For example quote the property names and set keep_quoted to true.