You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I'm trying to replace the options for the minimizer in angular-cli 7. But it doesn't seem to be working. No matter what config I set, the standard minimizer seems to be running.
Describe the solution you'd like
Is there a way to view the final webpack config output? I'm concerned I'm just appending another minimizer rather than replacing it. Or just an example of replacing the minimizer. I'm not 100% clear on how the "merging" of configs works.
Have you specified merge strategy replace for optimization? You might want to take a look at this comment.
Regarding viewing the final webpack config - not possible without changing the sources. I'm considering adding a debug or verbose option. Would be useful to me as well as to the users.
Reacted by Xiao (Bill) Li, Kyle J. Kemp and Benjamin Hoffmann
IMPORTANT!!!! :
Angular ignores terserOptions settings if differential loading (
browserlist must be equals:
0.5%
last 2 versions
Firefox ESR
not dead
not IE 9-11
not samsung 4
not android 4.4.3-4.4.4
not last 2 ie_mob versions
not last 2 op_mini versions
not last 2 op_mob versions
not last 2 baidu versions
not last 2 kaios versions
not last 2 and_uc versions
not last 2 and_qq versions
not last 2 edge versions
not chrome 49
) is enabled and target in tsconfig is higher than es5
@Xambey Your current example seems to work, however when I change it to keep_classnames it does not retain the class names. Any idea what might be the cause?
@Zundrium during the study of the sources it was found that specifically for Terser plugins, the builder ignores the mangling settings, all you can do is turn it off completely. You can read more here (read all correspondence)
So, for any newcomers a short recap of what's been discussed here and researched in the sources.
In order to change the minimizer settings you have to change the configuration of TerserPlugin. Nothing complicated, just the old good custom-webpack builder, read the docs.
HOWEVER, in order for these changes to be applied the differentialLoading must be switched off.
To do this you can either:
Completely drop the support for es5 by modifying browserlist file (only allow browsers that support es6).
Compile your code to es5 instead of es6, which will effectively support older versions of browsers but increase bundle size. This can be done by setting the target in tsconfig.json to es5 or not setting it at all (es5 is the default option for Angular).
Background: After the webpack build is done Angular is doing its own post-processing which disregards TerserPlugin options and does stuff like mangling in any case.
Reacted by Sanjiv Kumar, Jonathan Moosekian, Ryan Oberleitner, Fabian Scheidt, Simon Espigolé, Israpil Nalgiev and Simon Weaver
Activity
just-jeb commentedon Nov 16, 2018
Have you specified merge strategy
replaceforoptimization? You might want to take a look at this comment.Regarding viewing the final webpack config - not possible without changing the sources. I'm considering adding a
debugorverboseoption. Would be useful to me as well as to the users.RyanHow commentedon Nov 18, 2018
Thanks so much!. Worked like a charm. You are a legend.
Xambey commentedon Dec 25, 2019
The merge strategy no longer works, you should use a similar approach:
The default config for Angular 8:
IMPORTANT!!!! :
Angular ignores terserOptions settings if differential loading (
browserlist must be equals:
) is enabled and target in tsconfig is higher than es5
Default config
Zundrium commentedon Jan 14, 2020
@Xambey Your current example seems to work, however when I change it to
keep_classnamesit does not retain the class names. Any idea what might be the cause?Xambey commentedon Jan 14, 2020
@Zundrium during the study of the sources it was found that specifically for Terser plugins, the builder ignores the mangling settings, all you can do is turn it off completely. You can read more here (read all correspondence)
Zundrium commentedon Jan 20, 2020
@Xambey Alright, thanks.
just-jeb commentedon Jan 20, 2020
So, for any newcomers a short recap of what's been discussed here and researched in the sources.
In order to change the minimizer settings you have to change the configuration of
TerserPlugin. Nothing complicated, just the old goodcustom-webpackbuilder, read the docs.HOWEVER, in order for these changes to be applied the
differentialLoadingmust be switched off.To do this you can either:
es5by modifyingbrowserlistfile (only allow browsers that supportes6).es5instead ofes6, which will effectively support older versions of browsers but increase bundle size. This can be done by setting the target intsconfig.jsontoes5or not setting it at all (es5is the default option for Angular).Background:
After the webpack build is done Angular is doing its own post-processing which disregards
TerserPluginoptions and does stuff like mangling in any case.insel-maz commentedon Dec 16, 2021
As of Angular 12, it should be: