还可以使用 PurgeCSS
PurgeCSS 是一个用来删除未使用的 CSS 代码的工具。可以将它作为你的开发流程中的一个环节。 当你构建一个网站时,你可能会决定使用一个 CSS 框架,例如 TailwindCSS、Bootstrap、MaterializeCSS、Foundation 等,但是,你所用到的也只是框架的一小部分而已,大量 CSS 样式并未被使用。
接下来就该 PurgeCSS 上场了。PurgeCSS 通过分析你的内容和 CSS 文件,首先它将 CSS 文件中使用的选择器与内容文件中的选择器进行匹配,然后它会从 CSS 中删除未使用的选择器,从而生成更小的 CSS 文件。
安装
npm i -g purgecss
命令行使用
Usage: purgecss --css <css> --content <content> [options]例子
Options:
-con, --content <files> glob of content files
-css, --css <files> glob of css files
-c, --config <path> path to the configuration file
-o, --output <path> file path directory to write purged css files to
-font, --font-face option to remove unused font-faces
-keyframes, --keyframes option to remove unused keyframes
-rejected, --rejected option to output rejected selectors
-s, --safelist <list> list of classes that should not be removed
-h, --help display help for command
purgecss --css css/app.css css/palette.css --content src/index.html官网:https://www.purgecss.cn/
网友回复