UglifyJS icon indicating copy to clipboard operation
UglifyJS copied to clipboard

provide 'magic comments' to preserve classnames/function names

Open devdoomari3 opened this issue 7 years ago • 5 comments

Feature request: magic-comments to keep classnames/function names. eg).

// UGLIFYJS:KEEP_FUNCTION_NAME
class User extends Typegoose {
  ...
}

Why: I had problems with Webpack's uglifyjs mangling class names, when some libraries depended on constructor.name property to work.

specifically, when using Typegoose:

class User extends Typegoose { // 'User' becomes aqw, so it's stored as 'aqw' on mongodb
   // ..

related: https://github.com/webpack/webpack/issues/1659#issuecomment-415651353

devdoomari3 avatar Sep 21 '18 10:09 devdoomari3

  • keep_classnames (default: undefined) - pass true to prevent discarding or mangling of class names.

  • keep_fnames (default: false) - pass true to prevent discarding or mangling of function names. Useful for code relying on Function.prototype.name. If the top level minify option keep_classnames is undefined it will be overridden with the value of the top level minify option keep_fnames.

kzc avatar Oct 02 '18 15:10 kzc

@kzc but that means I have to edit the webpack build config, which is impossible for Create-React-App

Moreover, I don't want ALL the class names to be kept - only a few.

devdoomari3 avatar Oct 04 '18 04:10 devdoomari3

https://www.youtube.com/watch?v=oqMl5CRoFdk

kzc avatar Oct 04 '18 04:10 kzc

@kzc I like how you searched for such an apt song 👍

but... please-cat

please...?

devdoomari3 avatar Oct 04 '18 06:10 devdoomari3

Having such an option would be absolutely awesome.

llehn avatar Oct 30 '18 07:10 llehn