【问题标题】:grunt-postcss autoprefixer not adding prefixes but creates new filesgrunt-postcss autoprefixer 不添加前缀但创建新文件
【发布时间】:2016-01-27 12:11:23
【问题描述】:

我正在尝试将 grunt-postcss 与 autoprefixer 一起使用,但 css 没有得到前缀。 Autoprefixer 创建新文件,但不添加前缀。没有错误。

这是我的 gruntfile:

            postcss: {
                options: {
                    map: true,
                    processors: [
                        require('autoprefixer')({
                            browsers: ['last 2 versions']
                        })
                    ]
                },
                files: {
                    '<%= pathBuild %>/<%= pathAssets %>/<%= pathRio %>/css/rio-layout.prefixed.css': '<%= pathBuild %>/<%= pathAssets %>/<%= pathRio %>/css/rio-layout.css',
                    '<%= pathBuild %>/<%= pathAssets %>/<%= pathRio %>/css/theme.prefixed.css': '<%= pathBuild %>/<%= pathAssets %>/<%= pathRio %>/css/theme.css'
                }
            }

怎么了?

【问题讨论】:

    标签: gruntjs autoprefixer postcss


    【解决方案1】:

    在过去的几周里,这让我断断续续地发疯,我刚刚找到了一个适合我的答案。在 Bootstrap Gruntfile.js 中找到它。这就是我认为的问题所在:

    对于示例 grunt-postcss 示例,浏览器选项中的“最近 2 个版本”可能是一个占位符。当我从 Bootstrap Gruntfile.js 替换 browsers 数组时,我的 postcss 输出前缀开始匹配 Bootstrap dist css 文件的前缀。这是我使用的完整配置:

    grunt.initConfig({
      postcss: {
        options: {
          map: {
              inline: false,
          },
    
          processors: [
            require('autoprefixer')([
              "Android 2.3",
              "Android >= 4",
              "Chrome >= 20",
              "Firefox >= 24",
              "Explorer >= 8",
              "iOS >= 6",
              "Opera >= 12",
              "Safari >= 6"
            ]),
          ]
        },
        dist: {
          src: 'css/*.css'
        }
      }
    });
    

    【讨论】:

      【解决方案2】:

      也许你没有安装“autoprefixer”,或者它不在预期的文件夹中。

      确保您的 node_modules/ 文件夹具有与此类似的文件树:

      node_modules/
      ├── autoprefixer/
      │   └── . . .
      ├── postcss/
      │   └── . . .
      └── . . .
      

      如果您发现autoprefixer/ 丢失,则需要安装它。

      另一种可能是您安装的 autoprefixer 没有其依赖项(例如,autoprefixer/ 文件夹不包含其自己的 node_modules/ 文件夹)。通过使用以下命令重新安装来更正此问题:

      npm install autoprefixer --save-dev
      

      虽然不太可能,但您可能还需要使用 postcss 运行上述命令

      【讨论】:

      • 我用我的包,json-file 安装了依赖项,并获得了适当的文件夹结构,Autoprefixer 会创建新文件。 { "name": "***", "version": "1.1.0", "description": "***", "keywords": [ "*" ], "author": "***", "devDependencies": { "grunt": "~0.4.5", "grunt-contrib-clean": "latest", "grunt-contrib-concat": "latest", "grunt-contrib-copy": "latest", "grunt-contrib-less": "latest", "grunt-postcss": "latest", "autoprefixer": "latest", "grunt-contrib-uglify": "latest", "grunt-contrib-watch": "latest" } }
      猜你喜欢
      • 2017-07-23
      • 1970-01-01
      • 2016-03-29
      • 2020-04-11
      • 1970-01-01
      • 1970-01-01
      • 2015-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多