javascript - Node/Grunt - Autoprefixer - 如何将配置添加到我的 Gruntfile.js 以及如何检查支持的浏览器?

标签 javascript css node.js gruntjs vendor-prefix

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

经过一些周旋之后,我实际上得到了这个工作,这对我来说是相当惊人的,因为我是一个绝对的 Node 、咕噜和终端初学者。
autoprefixer documentation它说可以配置要支持的浏览器,因为给出了这行代码的解释:

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 输出有影响,但我不确定它是否正确?

此外,当我在命令行中键入 autoprefixer -i 以检查我的配置时,输出为 -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

关于javascript - Node/Grunt - Autoprefixer - 如何将配置添加到我的 Gruntfile.js 以及如何检查支持的浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19281182/

相关文章:

javascript - Python file.close() 和 with() 在高频循环中的行为

javascript - 汉堡包图标切换不起作用

javascript - jQuery 轮播幻灯片动画

node.js - 带有 Compass 的默认 Express 应用程序提供 ENOENT

javascript - REST API azure 语音转文本(已识别 : Text=undefined)

javascript - 警报到来时组合框消失

javascript - 使用 Angular 启用/禁用按钮

javascript - 将 Three.js 容器定位为 html div

mysql - 如何从对象动态设置mysql查询中的值?

javascript - 单击按钮时用 css 显示图像