CSS教程

[CSS] Purgecss to remove unused css

本文主要是介绍[CSS] Purgecss to remove unused css,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Install Purgecss to remove unused CSS

npm install @fullhuman/postcss-purgecss --save-dev

Edit postcss.config.js:

module.exports = {
  plugins: [
    require("tailwindcss"),
    require("autoprefixer"),
    process.env.NODE_ENV === "production" &&
      require("@fullhuman/postcss-purgecss")({
        // add all the html files
        content: ["./src/**/*.vue", "./public/index.html"],
        defaultExtractor: (content) => content.match(/[A-Za-z0-9-_:/]+/g) || [],
      }),
  ],
};

Then run npm run build, you will notice that the generate css file size down from 186602 lines to 600 lines.

这篇关于[CSS] Purgecss to remove unused css的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!