vladkens/autoprefixer

在PHP中使用node.js运行Autoprefixer。

v0.1 2015-01-30 11:55 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:55:35 UTC


README

Autoprefixer是一个用于解析CSS并为CSS规则添加厂商前缀的工具,它使用Can I Use的数据。这个库提供了与Node.js应用程序的PHP集成。

编写不带厂商前缀的CSS规则(实际上,完全可以忘记它们)

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

Autoprefixer会根据当前浏览器的流行度和属性支持数据为您应用前缀

a {
  -webkit-transition: -webkit-transform 1s;
  transition: -ms-transform 1s;
  transition: transform 1s
}

您可以通过电子邮件向我提出任何问题: vladkens@yandex.ru

安装

  • 首先您需要在服务器上安装Node.js

通过Composer安装。

  • 在项目根目录创建一个composer.json文件

    {
        "require": {
            "vladkens/autoprefixer": "dev-master"
        }
    }
  • 在项目根目录下编写

    Linux: php composer.phar install

    Windows: composer.bat install

  • index.php中写入

    require_once 'vendor/autoload.php';

使用方法

$autoprefixer = new Autoprefixer();
$css_one = 'a { color: black; }';
$css_two = 'a { color: white; }';

// If need compile one css. Function return compied CSS.
$prefixed = $autoprefixer->compile($css_one);
echo $prefixed;

// If need compile many css in one time. Function return array of compiled CSS.
$prefixed = $autoprefixer->([$css_one, $css_two]);
echo $prefixed[0] . "\n" . $prefixed[1];

// If occurred error in compile time Autoprefixer throw exception named `AutoprefixerException`.
// You need process it.
try {
    $autoprefixer->compile($css_one);
} catch (AutoprefixerException $error) {
    echo $error->getMessage();
} catch (Exception $error) {
    echo $error->getMessage();
}

// If you want to choose specific browsers
$autoprefixer = new Autoprefixer('last 1 version'); // one rule
// or 
$autoprefixer = new Autoprefixer(['ff > 2', '> 2%', 'ie 8']); // many rules
// or
$autoprefixer->setBrowsers('last 1 version');
// or change browsers on a one iteration
$autoprefixer->compile($css_one, 'last 1 version');

// Also, you can get latest version Autoprefixer using
$autoprefixer->update();

速度

在我的Intel i5-3210M 2.5GHz和5200 RPM HDD上,GitHub样式编译耗时390毫秒。

许可证

MIT

更多文档

查看https://github.com/ai/autoprefixer/blob/master/README.md