Reputation: 41
When compiling in angular 7 production mode I can't keep the class names. I tried the different parameters of the Terser plugin but none of them solve this problem. Is there a solution for this problem? Or is there another alternative to MyClass.constructor.name.
Thank you in advance
Below the custom Webpack configuration
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
keep_classnames: true,
mangle: false
}
})
]
}
};
Upvotes: 2
Views: 2023
Reputation: 31815
As any other optimized Javascript code, an Angular app in production mode goes through a minification process that changes all classes, functions and variables names to minimal ones (usually one letter) in order to reduce the loaded bundle size. So you can't rely on the obj.constructor.name
and compare it to a static value.
The clean, and "minification safe" alternative to obj.constructor.name === 'MyClass'
is obj instanceof Myclass
Upvotes: 2