[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.

上一篇:react 变量不用报错 no-unused-vars


下一篇:LeetCode 445 两数相加II 题解