I did some research recently about this, but I could not find any really safe way of how to remove unused CSS. However I came across some tools which would help you detect dead-code in VS Code. There is an extention which is not perfect but looks promising. Also I did some investigation of how to remove unused Angular Material CSS (if you use it) and created a video about it. You can check this out here.

But at least now (in 2020) there is no any reliable way to achieve what you want and see also an answer from Angular Core Team member about this topic


module.export={
  plugins: [
    new ExtractTextPlugin('[name].[contenthash].css'),
    // Make sure this is after ExtractTextPlugin!
    new PurifyCSSPlugin({
      // Give paths to parse for rules. These should be absolute!
      paths: glob.sync(path.join(__dirname, 'app/*.html')),
    })
  ]

};

install purifycss webpack first