Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Can't keep class names using uglifyjs-webpack-plugin with "mode": "production" #5

Closed
lgarron opened this issue Jul 12, 2018 · 1 comment

Comments

@lgarron
Copy link
Member

lgarron commented Jul 12, 2018

As soon as I set module.exports.mode = "production", class names are mangled.

Some references:
https://webpack.js.org/plugins/uglifyjs-webpack-plugin/
https://github.com/webpack-contrib/uglifyjs-webpack-plugin

Absolutely nothing works to keep the class names, including this overkill config:

plugins: [
  new UglifyJSPlugin({
    sourceMap: true,
    uglifyOptions: {
      keep_classnames: true,
      "mangle": {
        keep_classnames: true
      },
      "compress": {
        keep_classnames: true
      }
    }
  })
],

Or this one:

optimization: {
  minimizer: [
    new UglifyJSPlugin({
      sourceMap: true,
      uglifyOptions: {
        keep_classnames: true,
        "mangle": {
          keep_classnames: true
        },
        "compress": {
          keep_classnames: true
        }
      }
    })
  ]
},

I know that the config is being parsed properly, because I get errors if I place keep_classnames directly in the UglifyJSPlugin config object or change keep_classnames into a typo anywhere.

@lgarron lgarron changed the title Can't set keep_classnames on uglifyjs-webpack-plugin keep_classnames on uglifyjs-webpack-plugin doesn't work Jul 12, 2018
@lgarron lgarron changed the title keep_classnames on uglifyjs-webpack-plugin doesn't work Can't keep class names using uglifyjs-webpack-plugin with "mode": "production" Jul 12, 2018
@lgarron
Copy link
Member Author

lgarron commented Jul 12, 2018

Okay, I think I figured it out. An output target of ES5 in tsconfig.json was probably converting classes to functions before they reached UglifyJS, at which point keep_classnames did nothing.

Changing tsconfig.json to emit ES6 seems to work, although I still need to construct the production config from scratch instead of overwriting just the UglifyJS pluging.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant