Node / Grunt – Autoprefixer – 如何添加configuration到我的Gruntfile.js&如何检查支持的浏览器?

我想开始使用名为autoprefixer的CSS后处理器( https://github.com/ai/autoprefixer )。

经过一番杂耍,我实际上得到了这个工作,这对我来说是相当了不起的,因为我是一个绝对的节点,咕噜声和terminal初学者。
在autoprefixer文档中说,可以configuration哪些浏览器支持,作为解释这行代码给出:

autoprefixer("last 1 version", "> 1%", "ie 8", "ie 7").compile(css); 

但是我把这个代码放在哪里? 我试图把它粘贴到我的Gruntfile的底部而没有成功。 该文件如下所示:

 module.exports = function (grunt) { grunt.initConfig({ autoprefixer: { dist: { files: { 'build/style.css': 'style.css' } } }, watch: { styles: { files: ['style.css'], tasks: ['autoprefixer'] } } }); grunt.loadNpmTasks('grunt-autoprefixer'); grunt.loadNpmTasks('grunt-contrib-watch'); }; 

我也试着像这样添加它:

 autoprefixer: { options: { browsers: ["last 10 version", "> 1%", "ie 8", "ie 7"] }, dist: { files: { 'build/style.css': 'style.css' } }, 

这对CSS输出肯定有影响,但我不确定是否正确?

另外,当我在命令行inputautoprefixer -i来检查我的configuration时,输出是-bash: autoprefixer: command not foundgrunt-autoprefixer -i 。 我怎样才能解决这个问题? 我很想看到我支持的版本。
另一个变化就是这样做:

 inspect = autoprefixer("last 1 version").inspect(); console.log(inspect); 

但是,再次,这个代码放在哪里?

您需要全局安装autoprefixer以具有autoprefixer命令:

 sudo npm install -g autoprefixer autoprefixer -i 

现在,您可以从项目文件夹中使用Autoprefixer二进制文件,而无需全局安装Autoprefixer(不要忘记将grunt-autoprefixer更新到v0.4.1)。

在这里你可以findbrowsers选项说明。 选项可以是特定于目标或特定任务的,特定于目标的选项可以覆盖特定于任务的选项。