Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular-cli : How to ignore class names from being minified

For an application we need to keep the classname not minified because we use

var className = myObject.constructor.name;
export class myObject{ ... }

when we run

ng build -- pro

the class name gets minified in a random name.

like image 999
Emmanuel Avatar asked May 24 '17 14:05

Emmanuel


People also ask

What is MAngle in angular?

The MAngle class provides a fundamental type for the Maya API to hold and manipulate angular data. All API methods that require or return angular information do so through variables of this type.

What is Minification in angular?

Minification: In minification process following things are done within the js file to reduce the size of the js file for faster downloading. It removes all the white spaces within the file. It removes all the unwanted variables within the file. It converts all the big variable names to the smaller variable names.

What is Uglify in angular?

Hence those beautiful names, which are only made inorder for the code readability can be reduced to one or two letter variables. This process converts beautiful, human understandible variable names into ugly ones. Hence this process is called 'Uglification'. Angular also handles this process.


1 Answers

Angular cli builder supports NG_BUILD_MANGLE, NG_BUILD_MINIFY, NG_BUILD_BEAUTIFY node environment params (checked in version 8).

You can set them when running npm script in following way: env NG_BUILD_MANGLE=false NG_BUILD_MINIFY=false NG_BUILD_BEAUTIFY=true ng build --prod

This will result in unminified output, yet tree shaking and other optimizations will still be applied (compared to just turning off optimization).

like image 173
Pavel Gurecki Avatar answered Sep 23 '22 06:09

Pavel Gurecki