Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the Angular production build not shorten class names?

Is it possible to tell the Angular production build not to shorten class names?

Something like `ng serve -o --prod=true --abbreviateClassName=false

The issue I'm having is that I'm using this library:

https://github.com/fireflysemantics/validator/

It allows us to decorate class properties in order to validate them.

Since Angular shortens the class names I'm getting errors like this:

main.2876a5e2eb85f08784d9.js:1 Uncaught Error: The ValidationContainer 
      already contains context with signature t_e_sku.
    at Function.t.addValidationContext 

The decorators are keyed by ConstructorName_propertyName and since the Angular production build shortens the name this introduces conflicts when creating the validation contexts per the decorators.

like image 504
Ole Avatar asked Oct 24 '25 17:10

Ole


1 Answers

You can try disabling optimization:

https://github.com/angular/angular-cli/wiki/build

ng serve --prod --optimization=false

There is also an optimization flag for the builder configuration in the angular.json file:

      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "optimization": false

I'm not exactly sure if this flag is the same as the above.

I'm sure this will increase the bundle sizes. There aren't any finer grain controls here for this sort of thing, and I don't think a custom builder will help.

We haven't had the ng eject option to create a custom WebPack build for a while, but you might find some online examples of how to do it manually. It'll be a pain to update when Angular 9 comes out.

Maybe this library you're using was intended for NodeJS and not web browsers.

like image 104
Reactgular Avatar answered Oct 26 '25 07:10

Reactgular



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!