1

我对 grunt(和一般的 npm)很陌生,所以如果我错过了一些明显的东西,请原谅我!

我正在尝试设置我的 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.

这是我的 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

我错过了什么吗?(这是公然愚蠢的东西,比如放错地方的逗号不是吗!!)提前谢谢

4

1 回答 1

0

好的,所以如果有人碰巧遇到这个并且有类似的问题,这里是我的 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
于 2015-08-27T13:43:57.773 回答