如何检查重复的 CSS 规则?

2022-01-10 00:00:00 duplicates css redundancy

我搞砸了我的 css,不知何故我有很多重复的规则,而我的 1800 行 css 文件现在有 3000 多行..

I messed up my css and somehow i have a lot of the duplicate rules and my 1800 something lines css file is now of 3000+ lines..

是否有任何方法/工具可以将我的 css 文件作为输入并检查所有重复的规则?并可能生成一个 css 删除那些冗余?

Is there any way/tool that would take my css file as input and check for all the duplicate rules? and possibly generate a css removing those redundancies?

推荐答案

安装Node JShttps://nodejs.org/en/download/

如果您已经安装了 node js,或者在安装打开 node 命令提示符窗口后通过在 start 中键入 node(在 windows 机器上).

if you have already node js installed or after installing open node command prompt window by typing node( on windows machine) in start.

键入以下命令以安装 css purge 工具

Type following command to install css purge tool

npm install css-purge -g

npm install css-purge -g

工具安装后,

打开节点命令提示符窗口所在的文件夹并粘贴混乱的 css 文件,然后在节点命令提示符窗口中键入以下命令

Open the folder where node command prompt window is open and paste messed up css file there and then type following command in node cmd prompt window

css-purge -i style.css -o style_purged.css

css-purge -i style.css -o style_purged.css

其中 style.css 是混乱的 css 文件的名称,上面的命令将创建一个名为 style_purged.css 的新 css 文件,其中不包含重复的 css 规则.

where style.css is the name of messed up css file, the above command will create a new css file with name style_purged.css which does not contain duplicate css rules.

但要小心,它也会删除您的评论.https://www.npmjs.com/package/css-purge

But be careful, it will also remove the comments you have. https://www.npmjs.com/package/css-purge

相关文章