Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 7 minify assets with ng build --prod

JavaScript and CSS files in /assets are not minified after ng build --prod. Does someone know how I can minify those files? I don't see anything in the angular doc.

like image 280
user108828 Avatar asked Sep 11 '19 10:09

user108828


2 Answers

Everything you build in production are already minify if it not minify I think you havent turn on configuration in angular.json. You can use these config in your angular.json

"configurations": {
    "production": {
        "fileReplacements": [
            {
                "replace": "src/environments/environment.ts",
                "with": "src/environments/environment.prod.ts"
            }
        ],
        "optimization": true,
        "outputHashing": "all",
        "sourceMap": false,
        "extractCss": true,
        "namedChunks": false,
        "aot": true,
        "extractLicenses": true,
        "vendorChunk": true,
        "buildOptimizer": true,
        "serviceWorker": true,
        "deleteOutputPath": true,
        "budgets": [
            {
                "type": "initial",
                "maximumWarning": "2mb",
                "maximumError": "5mb"
            }
        ]
    }
}

Then run ng build --prod again

like image 74
Tony Ngo Avatar answered Oct 08 '22 15:10

Tony Ngo


When you run ng build --prod angular-cli creates a new folder named dist in your project folder. the dist is the folder that you upload to your server in order to deploy your project.

the assets folder is not minimized because there is no code to minimize in that folder, angular-cli does not minimize images, svgs text files etc ... if you want to minify images, you can search for online tools such as TinyJPG

edit:

Not necessarily mean that you want to minimize your images, but in your assets folder there shouldn't be any files which are .js .css .html .ts etc... only Jsons, images and other assets

like image 1
KLTR Avatar answered Oct 08 '22 17:10

KLTR