1

我使用composer安装了“autoPrefixer PHP”并尝试了github页面( https://github.com/vladkens/autoprefixer-php)中显示的示例。非常简单的例子

$autoprefixer = new Autoprefixer();
$css      = 'a { transition: transform 1s }';
$prefixed = $autoprefixer->compile($css);

只是输出 $css 不变。但是,如果我使用自定义参数初始化 autprefixer 对象,它会输出正确的前缀 css。

$autoprefixer = new Autoprefixer('last 2 versions');

还使用示例中所示的参数初始化对象,给出“未知浏览器要求'ie8'”错误

$autoprefixer = new Autoprefixer(array('ff > 2', '> 2%', 'ie8')); // many rules

那么我的安装有什么问题呢?其实我并没有手动做任何事情,只是由composer安装的。

4

2 回答 2

1

快速浏览一下vladkens Autoprefixer PHP编译方法的代码:

$nodejs = proc_open('node ' . __DIR__ . '/vendor/wrap.js',
    array(array('pipe', 'r'), array('pipe', 'w')),
    $pipes
);

好的,proc_open 节点 ..,它使用 Note.js,在 vladkens 自述文件的介绍中他写道:

该库提供 PHP 与 Node.js 应用程序的集成。

在自述文件安装部分他也写了

首先你需要在你的服务器上安装 Node.js。


看起来目前没有真正的 PHP 重建编译器,适用于没有自己的服务器的人、支持 Note.js 的主机、使用 Compass 等 Grunt/Gulp 的经验或没有用于CodeKit的 mac (不错的软件,以前找到它,但不能t 直接在 linux 上使用它)。

当我的 PHP 软件使用 scss、sass、less 或其他带有智能缓存的 css PHP 修改时,添加 autoprefixer 也是一个好主意。


结论

您需要服务器上的 Node.js 和在 PHP 中执行 proc_open() 的权限。

于 2015-04-24T22:25:09.930 回答
0

您需要在“ie”和“8”之间留一个空格,如示例中所示:

$autoprefixer = new Autoprefixer(array('ff > 2', '> 2%', 'ie 8')); // many rules
于 2015-03-31T12:59:34.773 回答