首页 文章

>> SyntaxError:意外的令牌:警告:找不到任务“默认”

提问于
浏览
0

我在gruntfile.js中有这个任务

当我运行时:grunt默认加载“gruntfile.js”任务......错误

SyntaxError:意外的令牌:警告:找不到任务“默认” . 使用--force继续 .

因警告而中止 .

我找不到我的代码中的错误在哪里 .

module.exports = function (grunt) {
  // Project configuration.
  grunt.initConfig({
    //uglify
    uglify: {
      options: {
        mangle: false,
        compress: {
          drop_console: true
        }
      },
      js: {
        files: [{
          cwd: 'assets/javascripts/',
          expand: true,
          src: '*.js',
          dest: 'assets/javascripts/min/'
        }]
      }
    }
 });


  sass: {
        // this is the "dev" Sass config used with "grunt watch" command
        dev: {
            options: {
                style: 'expanded',
                // tell Sass to look in the Bootstrap stylesheets directory when compiling
                loadPath: 'assets/stylesheets/sass/'
            },
            files: {
                // the first path is the output and the second is the input
                'sass/main.css': 'assets/styleheets/sass/main.scss'
            }
        },
        // this is the "production" Sass config used with the "grunt buildcss" command
        dist: {
            options: {
                style: 'compressed',
                loadPath: 'assets/stylesheets'
            },
            files: {
                'sass/main.css': 'assets/stylesheets/sass/main.scss'
            }
        }
    },
    // configure the "grunt watch" task
    watch: {
        sass: {
            files: 'sass/*.scss',
            tasks: ['sass:dev']
        }
    }
});
 // loadNpmTasks
 grunt.loadNpmTasks('grunt-contrib-uglify');
 grunt.loadNpmTasks('grunt-contrib-sass');
 grunt.loadNpmTasks('grunt-contrib-watch');

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

1 回答

  • 0

    您的定义没有正确嵌套,您应该在 grunt.initConfig 块中移动 sasswatch ,并将 grunt.registerTask, grunt.loadNpmTasks 指令移动到 function(grunt) {} 块的末尾,如下所示:

    module.exports = function (grunt) {
        grunt.initConfig({
             uglify: {},
             sass : {},
             watch : {}
        });
    
        grunt.loadNpmTasks('grunt-contrib-uglify');
        grunt.loadNpmTasks('grunt-contrib-sass');
        grunt.loadNpmTasks('grunt-contrib-watch');
    
        grunt.registerTask('default', ['uglify', 'watch', 'buildcss']);
    };
    

    Sample Gruntfile

相关问题