尽管提到了默认任务,但找不到任务默认值

时间:2017-07-21 12:01:09

标签: gruntjs

之前有一些问题要求,但我不能从中获得很多,因为我是grunt的新手。无论何时我运行代码,控制台如下所示

  

SyntaxError:无效或意外的令牌   警告:任务"默认"未找到。使用--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, {
  useminPrepare: 'grunt-usemin'
});
	
  // 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'
      ]
    }
  },

    useminPrepare: {
	html: 'app/menu.htm 
	},

useminPrepare: {
  html: 'app/menu.html',
  options: {
    dest: 'dist'
  }
},

// Concat
concat: {
  options: {
    separator: ';'
  },
  
  // dist configuration is provided by useminPrepare
  dist: {}
},

// Uglify
uglify: {
  // dist configuration is provided by useminPrepare
  dist: {}
},

cssmin: {
  dist: {}
},

// Filerev
filerev: {
  options: {
    encoding: 'utf8',
    algorithm: 'md5',
    length: 20
  },
  
  release: {
    // filerev:release hashes(md5) all assets (images, js and css )
    // in dist directory
    files: [{
      src: [
        'dist/scripts/*.js',
        'dist/styles/*.css',
      ]
    }]
  }
},
  
// Usemin
// Replaces all assets with their revved version in html and css files.
// options.assetDirs contains the directories for finding the assets
// according to their relative paths
usemin: {
  html: ['dist/*.html'],
  css: ['dist/styles/*.css'],
  options: {
    assetsDirs: ['dist', 'dist/styles']
  }
},
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',
  'useminPrepare',
  'concat',
  'cssmin',
  'uglify',
  'copy',
  'filerev',
  'usemin'
]);

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




1 个答案:

答案 0 :(得分:0)

您的grunt调用的完整输出显示您的gruntfile.js有一个sytax错误:

  

加载“gruntfile.js”任务......错误
  >> SyntaxError:无效或意外的令牌警告:未找到任务“default”。使用--force继续。

     

因警告而中止。

确实你的文件在 37

上没有收尾报价
useminPrepare: {
  html: 'app/menu.htm  <-----!!!!!!!!
},

useminPrepare: {
  html: 'app/menu.html',
  options: {
    dest: 'dist'
  }
},

可能是复制粘贴错误,因为你有两次 useminPrepare (这在严格模式下是非法的btw ...)