首页 文章

加载“gruntfile.js”任务...错误>> ReferenceError:未定义grunt

提问于
浏览
1

我的代码中存在问题 .

我在concole中写道:grunt connect

这是错误消息:

加载“gruntfile.js”任务......错误

ReferenceError:未定义grunt警告:未找到任务“connect” . 使用--force继续 .

因警告而中止 .


这是我的gruntfile.js文件:


module.exports = function(grunt) {
 // Project configuration.
 grunt.initConfig({
   pkg: grunt.file.readJSON('package.json'),
    connect: {
     uses_defaults: {}
   }

 });
 // Load Grunt plugins
 grunt.loadNpmTasks('');
 // Default task(s).
 grunt.registerTask('default', []);
};



// Load Grunt plugins
grunt.loadNpmTasks('grunt-contrib-connect');

我的代码有什么问题?为什么不找到连接任务?

1 回答

  • 0

    "Every Gruntfile (and gruntplugin) uses this basic format, and all of your Grunt code must be specified inside this function:" - https://gruntjs.com/getting-started

    module.exports = function(grunt) {
      // Do grunt-related things in here
    };
    

    在此函数中移动 grunt.loadNpmTasks('grunt-contrib-connect'); 应修复它 .

相关问题