警告:任务"默认"未找到。使用--force继续

时间:2017-05-23 16:12:59

标签: gruntjs postcss autoprefixer

我的gruntfile按预期工作,直到我在postcss和autprefixer中添加。我在https://www.npmjs.com/package/autoprefixer处完成了指南。但是我感到很害怕:

Loading "gruntfile.js" tasks...ERROR
>> TypeError: undefined is not a function
Warning: Task "default" not found. Use --force to continue.

我的gruntfile看起来像这样:

module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
  dist: {
    files: {
        "js/wd.min.js" : [
            "node_modules/foundation-sites/dist/js/plugins/foundation.core.min.js",
            "node_modules/foundation-sites/dist/js/plugins/foundation.util.mediaQuery.js",
            "node_modules/foundation-sites/dist/js/plugins/foundation.util.timerAndImageLoader.js",
            "node_modules/foundation-sites/dist/js/plugins/foundation.equalizer.min.js",
            "js/wd.js"
        ]
    },
    options: {
        beautify:true,
        compress:false
    }
  }
},
watch: {
    dist: {
        files: [
            /* JS locations */
            "js/wd.js",

            /* SCSS locations */
            "style/**/*.scss",
        ],
        tasks: [
            "uglify",
            "sass_imports",
            "sass",
            "postcss"
        ]
    }
},
sass: {
    options: {
        loadPath: [
            'node_modules/foundation-sites/scss',
            require("bourbon").includePaths
        ],
    },
    dist: {
        files: {
            "style/style.css" : [
                "style/style.scss",
            ],
        },
        options: {
            require: "sass-css-importer"
        }
    }
},
sass_imports: {
    dist: {
        src: [
            "style/style.scss"
        ],
        dest: "all.scss"
    }
},
postcss: {
    options: {
        map: true,
        processors: [
            require('autoprefixer')({browsers: 'last 2 versions'})
        ]
    },
    dist: {
        src: "style/style.css"
    }
}
});

grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-scss-imports');
grunt.loadNpmTasks('grunt-postcss');

//load watch plugin

// Default task(s).
grunt.registerTask('default', ['watch']);
};

我遇到的所有解决方案都引用了一个错字,但我无法看到它。任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:0)

undefined不是函数暗示

require('autoprefixer')没有退回功能 - 请检查它是否正确安装

OR

grunt.initConfig不是一个功能。当你运行这段代码时,你是否正在传递咕噜声?例如require('gruntfile.js')(grunt)

我认为通常你不会将你的gruntfile代码包装在一个函数中 - getting started example似乎没有,如果你只是从命令运行grunt,它可能会打开它换行,而不是在此配置中加载并传入grunt。