Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gruntjs grunt postcss autoprefixer不添加前缀,而是创建新文件_Gruntjs_Autoprefixer_Postcss - Fatal编程技术网

Gruntjs grunt postcss autoprefixer不添加前缀,而是创建新文件

Gruntjs grunt postcss autoprefixer不添加前缀,而是创建新文件,gruntjs,autoprefixer,postcss,Gruntjs,Autoprefixer,Postcss,我正在尝试将grunt PostCs与autoprefixer一起使用,但是css没有前缀。Autoprefixer创建新文件,但不带前缀。没有错误 这是我的Grunfile文件: postcss: { options: { map: true, processors: [ require('autoprefixe

我正在尝试将grunt PostCs与autoprefixer一起使用,但是css没有前缀。Autoprefixer创建新文件,但不带前缀。没有错误

这是我的Grunfile文件:

            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'
                }
            }
邮政编码:{
选项:{
地图:没错,
处理器:[
需要('autoprefixer')({
浏览器:[“上两个版本”]
})
]
},
档案:{
“///css/rio layout.prefixed.css”:“///css/rio layout.css”,
“///css/theme.prefixed.css”:“///css/theme.css”
}
}

怎么了?

可能您没有安装“AutoRefixer”,或者它不在预期的文件夹中

确保您的
节点\u modules/
文件夹具有与此类似的文件树:

node_modules/
├── autoprefixer/
│   └── . . .
├── postcss/
│   └── . . .
└── . . .
如果发现缺少
autoprefixer/
,则需要安装它

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

npm install autoprefixer --save-dev

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

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

在grunt postcss示例中,浏览器选项中的“最后2个版本”可能是一个占位符。当我从Bootstrap Gruntfile.js替换浏览器数组时,我的postscs输出前缀开始匹配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'
    }
  }
});

我用我的包json文件安装了依赖项,并获得了适当的文件夹结构,Autoprefixer创建了新文件<代码>{“名称”:“***”,“版本”:“1.1.0”,“描述”:“***”,“关键词”:[“*”],“作者”:“***”,“开发依赖”:{“grunt”:“~0.4.5”,“grunt contrib clean”:“最新”,“grunt contrib concat”:“最新”,“grunt contrib副本”:“最新”,“grunt contrib less”:“最新”,“grunt Postss”:“最新”,“autoprefixer”:“latest”,“grunt contrib uglify”:“latest”,“grunt contrib watch”:“latest”}