项目作者: aigoncharov

项目描述 :
Angular builder that allows Terser (Uglify) customization
高级语言: TypeScript
项目地址: git://github.com/aigoncharov/angular-builder-custom-terser-options.git
创建时间: 2019-02-20T12:00:43Z
项目社区:https://github.com/aigoncharov/angular-builder-custom-terser-options

开源协议:MIT License

下载


angular-builder-custom-terser-options

Custom Angular builder that allows Terser (Uglify) customization. It’s a sub-class of Angular’s default builder and it does a very small customization of its logic by extending final webpack config with your custom options for Terser.

This project is not maintained. Try https://github.com/just-jeb/angular-builders instead

Quick start

  1. Install

    1. npm i -D angular-builder-custom-terser-options

    For a builder compatible with Angular 7 run npm i -D angular-builder-custom-terser-options@1

  2. Add builders from this package to your angular.json.

    1. Set projects.yourProjectName.architect.build to angular-builder-custom-terser-options:browser-custom-terser
    2. Set projects.yourProjectName.architect.build.configurations.production.optimization to true
    3. Set projects.yourProjectName.architect.build.configurations.production.terserOptions to an object with any minify options supported by Terser. You can find the list of available options here.
    4. Set projects.yourProjectName.architect.serve to angular-builder-custom-terser-options:dev-server-custom-terser
    1. {
    2. // ... rest of the default config ,
    3. "projects": {
    4. "yourProjectName": {
    5. "architect": {
    6. "build": {
    7. // Set our custom builder here
    8. "builder": "angular-builder-custom-terser-options:browser-custom-terser",
    9. "options": {
    10. // Your default options. Leave it as is
    11. },
    12. "configurations": {
    13. "production": {
    14. // Add any options supported by Terser here
    15. "terserOptions": {
    16. "keep_classnames": true
    17. },
    18. // Enable optimization to enable Terser itself
    19. "optimization": true
    20. }
    21. }
    22. },
    23. "serve": {
    24. // Set our custom builder here
    25. "builder": "angular-builder-custom-terser-options:dev-server-custom-terser"
    26. // Rest of the config. Leave it as is
    27. }
    28. }
    29. }
    30. }
    31. }

Common use-cases

Keep class names

If you set target in your tsconfig.json to es6 or higher, set your terserOptions to { "keep_classnames": true }.
If you set target in your tsconfig.json to es5, set your terserOptions to { "keep_fnames": true }.