简体   繁体   English

grunt-autoprefixer设置

[英]grunt-autoprefixer setup

i'm very new to grunt (and npm in general) so forgive me if I've missed something glaringly obvious! 我是新来的(通常是npm),所以请原谅我,如果我错过了明显的事情!

I'm trying to set up my gruntfile (which has been working just fine before I started this particular challenge) to use the autoprefixer plugin, I followed the instructions on this blog http://grunt-tasks.com/autoprefixer/ but I'm receiving this error when i try and initialize grunt : 我正在尝试设置我的gruntfile(在开始此特殊挑战之前一直工作良好)以使用autoprefixer插件,我按照此博客http://grunt-tasks.com/autoprefixer/上的说明进行操作,但我我尝试初始化grunt时收到此错误:

 $ grunt

Running "postcss:dist" (postcss) task

Warning: Cannot read property 'postcss' of undefined Use --force to continue.

Aborted due to warnings.

And here is my gruntfile : 这是我的gruntfile:

module.exports = function(grunt) {

grunt.loadNpmTasks('grunt-contrib-uglify');

grunt.loadNpmTasks('grunt-contrib-watch');

grunt.loadNpmTasks('grunt-contrib-compass');

var autoprefixer = require('autoprefixer-core');

require('load-grunt-tasks')(grunt);

grunt.initConfig ({

uglify: {

my_target: {

files: {

'_/js/script.js' : ['_/components/js/*.js']

} //files

} //my_target

}, //uglify

compass: {

dev: {

options: {

config: 'config.rb'

} //options

}//dev

}, //compass

watch: {

options: {livereload: true},

scripts: {

files: ['_/components/js/*.js'],

tasks: ['uglify']

}, //script

sass: {

files: ['_/components/sass/*.scss'],

tasks: ['compass:dev']

}, //sass

html: {

files: ['*.html'],

}

}, //watch

postcss: {

options: {

processors: [

autoprefixer({

browers: ['> 0.5%', 'last 2 versions', 'Firefox ESR', 'Opera 12.1']

}).postcss

]

},

dist: {

files: {

'_/css/styles.css': '_/components/sass/*.scss'

}

}

}

}); //initConfig

grunt.registerTask('default', 'watch', ['postcss']);

} //exports

Am I missing something? 我想念什么吗? (it's blatantly something stupid like a misplaced comma isnt it!!) Thanks In advance (这是一个愚蠢的东西,像放错逗号不是吗!)谢谢

Ok so if anyone happens to stumble across this and has a similar problem here is my gruntfile that shows how i fixed the problem. 好吧,如果有人碰巧碰到了这个问题,并且有类似的问题,这是我的gruntfile,它显示了我如何解决此问题。

module.exports = function(grunt) {
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-compass');
    grunt.loadNpmTasks('grunt-postcss');
    grunt.initConfig ({
        uglify: {
            my_target: {
                files: {
                    '_/js/script.js' : ['_/components/js/*.js']
                } //files
            } //my_target
        }, //uglify
        compass: {
            dev: {
                options: {
                    config: 'config.rb'
                } //options
            }//dev
        }, //compass
        watch: {
            options: {livereload: true},
            scripts: {
                files: ['_/components/js/*.js'],
                tasks: ['uglify']
            }, //script
            sass: {
                files: ['_/components/sass/*.scss'],
                tasks: ['compass:dev']
            }, //sass
            html: {
                files: ['*.html'],
            }
        }, //watch
        postcss: {
            options: {
                map: true,
                processors: [
                    require('autoprefixer-core')({
                        browsers: ['last 2 versions']
                    })
                ]
            },
            dist: {
                src: '_/css/*.css'
            }
        }
    }); //initConfig
    grunt.registerTask('default', 'watch', ['postcss:dist']);
} //exports

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM