CSS 组合文件 &压缩

发布于 2024-12-11 19:34:01 字数 453 浏览 0 评论 0原文

我希望能够在构建时提交一组 CSS 文件并完成以下操作:

  • 将所有 CSS 文件合并到一个 CSS 文件中
  • 合并所有重叠的选择器
  • 删除所有注释
  • 删除不必要的空白
  • 删除空样式

我确信还有其他的,但这就是我要开始的。

这是我希望如何访问该工具的优先顺序:

  1. 远程网站
  2. Web 托管安装 - 与我的网站相同 (Debian/PHP 5.2.12)
  3. 本地计算机安装 (Windows 7)

我看到 CSS 压缩器,但它似乎没有组合 CSS 文件,也没有组合重叠的 CSS 选择器。

提前致谢。

I want to be able to, at build-time, submit a group of CSS files and have the following done:

  • Combine all CSS files into one CSS file
  • Combine all overlapping selectors
  • Remove all comments
  • Remove unnecessary white space
  • Remove empty styles

I'm sure there are others, but this what I'm starting with.

This is the preference order of how I would like to access the tool:

  1. Remote Website
  2. Web Hosted Installed - same as my website (Debian/PHP 5.2.12)
  3. Local Machine Installed (Windows 7)

I saw CSS Compressor, but it doesn't seem to combine CSS files nor does it combine overlapping CSS selectors.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

往日 2024-12-18 19:34:01

我会推荐 YUI 压缩器 因为它被广泛使用并且具有命令行界面。

您还应该考虑使构建过程自动化,以便您可以使用单个命令构建所有内容。如果您不想使用现有的构建工具,您可以为此类任务创建一个简短的 .bat 文件。


首先,合并文件:

type file1.css file2.css file3.css > combined.css

然后将其传递给 YUI 压缩器:

java -jar yuicompressor.jar combined.css > combined-min.css

I would recommend the YUI compressor since it is widely used and has a command line interface.

You should also consider making your build process automated so that you can build everything with a single command. If you don't want to use an existing build tool you could create a short .bat file for this kind of task.


First, combine your files:

type file1.css file2.css file3.css > combined.css

then pass it to the YUI compressor:

java -jar yuicompressor.jar combined.css > combined-min.css
溇涏 2024-12-18 19:34:01

您可以尝试 Chirpy。它将 结合压缩 文件,v2 有一个 命令行界面

不过我只在 Visual Studio 中运行过它。

You could try Chirpy. It will combine and compress files and v2 has a command line interface.

I've only ever run it within Visual Studio though.

且行且努力 2024-12-18 19:34:01

您应该使用 sCSSOptimizer

  • 示例

如果你想编译多个 css 文件,就这样做

<?php
require('./sCSSOptimizer/scssoptimizer.class.php');

$css1 = file_get_contents("./cssfile1.css");
$css2 = file_get_contents("./cssfile2.css");

$final_css = $css1.$css2; //you can join more, if you want...

$scss = new sCSSOptimizer($final_css);

//$compression_rate = $scss->getCompressionRate();

$compressed_css = $scss->getOptimized();
//do your stuff
?>

You should use sCSSOptimizer.

  • Example

If you want to compile more than one css files than do like this

<?php
require('./sCSSOptimizer/scssoptimizer.class.php');

$css1 = file_get_contents("./cssfile1.css");
$css2 = file_get_contents("./cssfile2.css");

$final_css = $css1.$css2; //you can join more, if you want...

$scss = new sCSSOptimizer($final_css);

//$compression_rate = $scss->getCompressionRate();

$compressed_css = $scss->getOptimized();
//do your stuff
?>

.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文