Gruntfile.js语法错误:警告:找不到任务“默认”。使用--force继续

时间:2017-08-03 18:55:47

标签: gruntjs

这是我第一次尝试配置Gruntfile.js,我似乎无法弄清楚是什么原因造成“警告:任务”默认“未找到。使用--force继续。由于警告而中止。”错误。有人可以帮我弄清楚我的代码有什么问题。查找以下源代码:

    'use strict';

    module.exports = function (grunt) {

    // Time how long tasks take. Can help when optimizing build times
    require('time-grunt')(grunt);

    // Automatically load required Grunt tasks
    require('jit-grunt')(grunt);

    // Define the configuration for all the tasks
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

   // Make sure code styles are up to par and there are no obvious mistakes
          jshint: {
            options: {
              jshintrc: '.jshintrc',
              reporter: require('jshint-stylish')
            },

            all: {
              src: [
                'Gruntfile.js',
                'app/scripts/{,*/}*.js'
              ]
            }
          }      
    }),

    copy: {
    dist: {
    cwd: 'app',
    src: [ '**','!styles/**/*.css','!scripts/**/*.js' ],
    dest: 'dist',
    expand: true
    },

    fonts: {
    files: [
      {
        //for bootstrap fonts
        expand: true,
        dot: true,
        cwd: 'bower_components/bootstrap/dist',
        src: ['fonts/*.*'],
        dest: 'dist'
      }, {
        //for font-awesome
        expand: true,
        dot: true,
        cwd: 'bower_components/font-awesome',
        src: ['fonts/*.*'],
        dest: 'dist'
      }
    ]
    }
    },

    clean: {
    build: {
    src: [ 'dist/']
    }
    });


    grunt.registerTask('build', [
    'clean',
    'jshint',
    'copy'
    ]);


        grunt.registerTask('build', [
      'jshint'
    ]);

    grunt.registerTask('default',['build']);

    };

2 个答案:

答案 0 :(得分:0)

您尚未定义名为default的任务。一个样本,非常小的gruntfile.js可以在下面找到:

.meteor/packages

因此,在这个文件中,我正在加载名为module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-copy'); grunt.initConfig({ copy: { main: { files: [ { expand: true, src: ['**'], cwd: 'lib/font-awesome/fonts/', dest: 'fonts/', filter: 'isFile' }, ] } } }); grunt.registerTask('default', ['copy:main']); }; 的NPM包。然后在配置中,我指定复制子任务的配置,给它命名为main,并包括下面的规则。每个grunt子任务都有自己的选项和配置格式,您可以遵循。最后,我说Grunt任务运行器应该有一个名为default的任务,后跟一个操作顺序。我的第一个(也是唯一的)是复制子任务和主规则集。在您的情况下,这可能是复制:dist用于复制操作。

希望有助于您入门。

答案 1 :(得分:0)

我发现了语法错误。这些字符'};'将配置关闭在错误的位置(第30行),这破坏了程序的流程。所以我只需要将它们移除并将它们放在67号线上的合适位置。

对不起,这对我来说只是一个愚蠢的错误,可能与其他任何人都无关。

相关问题