How to integrate PurgeCSS with Angular CLI project

前端 未结 4 1995
后悔当初
后悔当初 2021-02-04 13:30

I have an Angular project created with Angular CLI, so I have angular.json file for configuring the build.

I wanted to integrate PurgeCSS as it seems to be a great tool

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 14:12

    You can simply run the following commands in your project root directory

    npm i -D postcss-import postcss-loader postcss-scss
    ng add ngx-build-plus
    

    In angular.json, make the following replacements in "architect" section:

    "builder": "@angular-devkit/build-angular:browser" with "builder": "ngx-build-plus:browser" under "build",

    "builder": "@angular-devkit/build-angular:dev-server" with "builder": "ngx-build-plus:dev-server" under "serve",

    "builder": "@angular-devkit/build-angular:karma" with "builder": "ngx-build-plus:karma" under "test",

    You should also add "extraWebpackConfig": "webpack.config.js" under options in the respected sections.

提交回复
热议问题