问题描述
我正在尝试使用带有 grunt 的 PostCSS 插件自动前缀。我浏览了许多相关的文章和 Stackoverflow 的答案,但我仍然收到“警告:[对象对象] 不是 PostCSS 插件使用 --force 继续”。
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),sass: {
dist: {
files: {
'css/style.css' : 'scss/style.scss'
}
}
},watch: {
css: {
files: '**/*.scss',tasks: ['sass']
}
},postcss: {
options: {
map: true,processors: [
require('autoprefixer')()
]
},dist: {
src: 'css/*.css'
}
}
});
grunt.loadNpmtasks('grunt-contrib-sass');
grunt.loadNpmtasks('grunt-contrib-watch');
grunt.loadNpmtasks('grunt-postcss');
grunt.registerTask('dev',['sass','watch']);
grunt.registerTask('build','postcss']);
}
package.json
"devDependencies": {
"grunt": "^1.4.0","grunt-contrib-sass": "^2.0.0","grunt-contrib-watch": "^1.1.0","grunt-postcss": "^0.9.0","postcss": "^8.3.0","autoprefixer": "^10.2.6"
}
I am a newbie so please help.
解决方法
尚不确定根本原因是什么,但将 autoprefixer 降级到版本 9 可以解决问题
package.json
"devDependencies": {
"grunt": "^1.4.0","grunt-contrib-sass": "^2.0.0","grunt-contrib-watch": "^1.1.0","grunt-postcss": "^0.9.0","postcss": "^8.3.0","autoprefixer": "^9.8.6"
}