Grunt usemin警告:对象没有方法'包含'

时间:2016-01-25 14:39:17

标签: grunt-usemin

我正在使用Grunt任务运行器,而Gruntfile.js“如下:

'use strict';

module.exports = function(grunt){

require('time-grunt')(grunt);

require('jit-grunt')(grunt, {
    useminPrepare: 'grunt-usemin'
});

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    jshint: {
        options: {
            jshintrc: '.jshintrc',
            reporter: require('jshint-stylish')
        },
        all: {
            src: ['Gruntfile.js', 'app/scripts/{,*/}*.js']
        }
    },
    useminPrepare: {
        html: 'app/menu.html',
        options: {
            dest: 'dist'
        }
    },

    concat: {
        options: {
            separator: ';'
        },
        dist:{}
    },

    uglify:{
        dist:{}
    },

    cssmin: {
        dist:{}
    },

    filerev: {
        options: {
            encoding: 'utf8',
            algorithm: 'md5',
            length: 20
        },
            release: {
                files:[{
                src: ['dist/scripts/*.js', 'dist/styles/*.css']
            }]
        }

    },

    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: [
                {
                    expand: true,
                    dot: true,
                    cwd: 'bower_components/bootstrap/dist',
                    src: ['fonts/*.*'],
                    dest: 'dist'
                },
                {
                    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']);



};

问题是当grunt执行usemin时,它会显示以下警告并中止任务:
enter image description here

我无法确切地知道问题的确切位置,因此我不知道还需要提供多少代码。我是初学者。

更新:

这是我在项目中使用的自己的脚本:

'use strict';

angular.module('confusionApp', []).controller('menuController', function(){
        var dishes=[
                                                 {
                                                   name:'Uthapizza',
                                                   image: 'images/uthapizza.png',
                                                   category: 'mains',
                                                   label:'Hot',
                                                   price:'4.99',
                                                   description:'A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.',
                                                   comment: ''
                                                },
                                                {
                                                   name:'Zucchipakoda',
                                                   image: 'images/zucchipakoda.png',
                                                   category: 'appetizer',
                                                   label:'',
                                                   price:'1.99',
                                                   description:'Deep fried Zucchini coated with mildly spiced Chickpea flour batter accompanied with a sweet-tangy tamarind sauce',
                                                   comment: ''
                                                },
                                                {
                                                   name:'Vadonut',
                                                   image: 'images/vadonut.png',
                                                   category: 'appetizer',
                                                   label:'New',
                                                   price:'1.99',
                                                   description:'A quintessential ConFusion experience, is it a vada or is it a donut?',
                                                   comment: ''
                                                },
                                                {
                                                   name:'ElaiCheese Cake',
                                                   image: 'images/elaicheesecake.png',
                                                   category: 'dessert',
                                                   label:'',
                                                   price:'2.99',
                                                   description:'A delectable, semi-sweet New York Style Cheese Cake, with Graham cracker crust and spiced with Indian cardamoms',
                                                   comment: ''
                                                }
                                            ];
        this.dishes = dishes;
        this.tab = 1;
        this.filtText = '';
        this.select = function(setTab){
          this.tab = setTab;

          if(setTab === 2){
            this.filtText = "appetizer";
          }
          else if(setTab === 3){
            this.filtText = "mains";
          }
          else if(setTab === 4){
            this.filtText = "dessert";
          }
          else{
            this.filtText = "";
          }
        };
        this.isSelected = function(isTab){
          if(this.tab === isTab){
            return true;
          }
          return false;
        };
    });
更新

这是我得到的错误的堆栈跟踪。

Running "usemin:html" (usemin) task
Warning: Object  has no method 'contains' Use --force to continue.
TypeError: Object  has no method 'contains'
at replaceWith (E:\Study\Front End JS Framework         AngularJS\conFusion\node_modules\grunt-usemin\lib\fileprocessor.js:170:16)
at null.<anonymous> (E:\Study\Front End JS Framework AngularJS\conFusion\node_modules\grunt-usemin\lib\fileprocessor.js:157:45)
at Array.forEach (native)
at replaceBlocks (E:\Study\Front End JS Framework AngularJS\conFusion\node_modules\grunt-usemin\lib\fileprocessor.js:155:15)
at FileProcessor.process (E:\Study\Front End JS Framework AngularJS\conFusion\node_modules\grunt-usemin\lib\fileprocessor.js:239:45)
at E:\Study\Front End JS Framework AngularJS\conFusion\node_modules\grunt-usemin\tasks\usemin.js:141:31
at Array.forEach (native)
at E:\Study\Front End JS Framework AngularJS\conFusion\node_modules\grunt-usemin\tasks\usemin.js:135:13
at Array.forEach (native)
at Object.<anonymous> (E:\Study\Front End JS Framework AngularJS\conFusion\node_modules\grunt-usemin\tasks\usemin.js:130:16)

1 个答案:

答案 0 :(得分:1)

问题在于您使用的usemin版本。事实证明,在usemin中将3.1.1版本从3.0.0更改为package.json可以解决问题。我最好的选择是你的代码没有问题,但你的usemin中有fileprocessor.js文件。更改版本可以解决问题。

在package.json上更改usemin版本并运行npm install