我正在使用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](https://istack.dev59.com/iUuzg.webp)
更新:
这是我在项目中使用的自己的脚本:
'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)