Grunt返回错误“找不到*目标。”或“找不到任务*”。完成所有任务。 grunt --help也没有显示某些可用的任务,例如“build”和“test”任务。
此配置似乎以前正在运行。但它没有改变(git确保这一点)。
它出了什么问题?
这是我的Gruntfile.js:
module.exports = function(grunt) {
require('time-grunt')(grunt);
require('load-grunt-tasks')(grunt);
grunt.initConfig({
yeoman: {
app: 'app',
dist: 'dist'
},
phonegap: {
config: {
root: 'dist',
config: 'config.xml',
cordova: '.cordova',
path: 'phonegap',
plugins: [],
platforms: ['ios', 'android', 'wp8'],
verbose: false
}
},
compass: {
server: {
options: {
sassDir: '<%= yeoman.app %>/styles/',
cssDir: '.tmp/styles/'
}
},
},
watch: {
compass: {
files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
tasks: ['compass:server', 'autoprefixer']
},
styles: {
files: ['<%= yeoman.app %>/styles/{,*/}*.css'],
tasks: ['copy:styles', 'autoprefixer']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: ['<%= yeoman.app %>/*.html', '.tmp/styles/{,*/}*.css', '{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js', '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}']
}
},
connect: {
options: {
port: 9000,
livereload: 35729,
hostname: 'localhost'
},
livereload: {
options: {
open: true,
base: ['.tmp', '<%= yeoman.app %>']
}
},
test: {
options: {
base: ['.tmp', 'test', '<%= yeoman.app %>']
}
},
dist: {
options: {
open: true,
base: '<%= yeoman.dist %>'
}
}
},
clean: {
dist: {
files: [{
dot: true,
src: ['.tmp', '<%= yeoman.dist %>/*', '!<%= yeoman.dist %>/.git*']
}]
},
server: '.tmp'
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: ['Gruntfile.js', '<%= yeoman.app %>/scripts/{,*/}*.js', '!<%= yeoman.app %>/scripts/vendor/*'
// 'test/spec/{,*/}*.js'
]
},
karma: {
options: {
files: ['test/**/*.js']
},
continuous: {},
dev: {}
},
mocha: {
all: {
options: {
run: true,
urls: ['http://<%= connect.test.options.hostname %>:<%= connect.test.options.port %>/index.html']
}
}
},
autoprefixer: {
options: {
browsers: ['last 1 version']
},
dist: {
files: [{
expand: true,
cwd: '.tmp/styles/',
src: '{,*/}*.css',
dest: '.tmp/styles/'
}]
}
},
'bower-install': {
app: {
html: '<%= yeoman.app %>/index.html',
ignorePath: '<%= yeoman.app %>/'
}
},
rev: {
dist: {
files: {
src: ['<%= yeoman.dist %>/scripts/{,*/}*.js', '<%= yeoman.dist %>/styles/{,*/}*.css', '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp}', '<%= yeoman.dist %>/styles/fonts/{,*/}*.*']
}
}
},
useminPrepare: {
options: {
dest: '<%= yeoman.dist %>'
},
html: '<%= yeoman.app %>/index.html'
},
usemin: {
options: {
dirs: ['<%= yeoman.dist %>']
},
html: ['<%= yeoman.dist %>/{,*/}*.html'],
css: ['<%= yeoman.dist %>/styles/{,*/}*.css']
},
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '{,*/}*.{png,jpg,jpeg}',
dest: '<%= yeoman.dist %>/images'
}]
}
},
svgmin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '{,*/}*.svg',
dest: '<%= yeoman.dist %>/images'
}]
}
},
cssmin: {
},
htmlmin: {
dist: {
options: {
},
files: [{
expand: true,
cwd: '<%= yeoman.app %>',
src: '*.html',
dest: '<%= yeoman.dist %>'
}]
}
},
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: ['*.{ico,png,txt}', '.htaccess', 'images/{,*/}*.{webp,gif}', 'res/**', 'styles/fonts/{,*/}*.*', 'bower_components/**']
}]
},
styles: {
expand: true,
dot: true,
cwd: '<%= yeoman.app %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
}
},
concurrent: {
server: [/*'copy:styles'*/ 'compass'],
test: [/*'copy:styles'*/ 'compass'],
dist: [/*'copy:styles'*/ 'compass', 'imagemin', 'svgmin', 'htmlmin']
}
});
grunt.registerTask('server', function(target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run(['clean:server', 'concurrent:server', 'autoprefixer', 'connect:livereload', 'watch']);
});
grunt.registerTask('test', ['clean:server', 'concurrent:test', 'autoprefixer', 'connect:test', 'mocha']);
grunt.registerTask('build', ['clean:dist', 'useminPrepare', 'concurrent:dist', 'autoprefixer', 'concat', 'cssmin', 'uglify', 'copy:dist', 'rev', 'usemin']);
grunt.registerTask('platform-build', ['default', 'phonegap:build']);
grunt.registerTask('default', ['jshint',
'build'
]);
};
任务从我的package.json中加载了require('load-grunt-tasks')(grunt):
{
"name": "",
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"bower": "~1.3.12",
"coffeelint": "^1.6.0",
"grunt": "~0.4.1",
"grunt-autoprefixer": "~0.3.0",
"grunt-concurrent": "~1.0.0",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-coffee": "~0.12.0",
"grunt-contrib-compass": "~1.0.1",
"grunt-contrib-concat": "~0.5.0",
"grunt-contrib-connect": "^0.8.0",
"grunt-contrib-copy": "~0.7.0",
"grunt-contrib-handlebars": "^0.9.0",
"grunt-contrib-htmlmin": "~0.3.0",
"grunt-contrib-imagemin": "~0.8.1",
"grunt-contrib-requirejs": "^0.4.4",
"grunt-contrib-uglify": "~0.6.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-karma": "~0.9.0",
"grunt-mocha": "~0.4.11",
"grunt-newer": "^0.7.0",
"grunt-notify": "^0.3.1",
"grunt-phonegap": "~0.15.2",
"grunt-svgmin": "~1.0.0",
"load-grunt-config": "^0.13.2",
"load-grunt-tasks": "~0.6.0",
"time-grunt": "~1.0.0"
},
"engines": {
"node": ">=0.10.0"
}
}
使用npm install安装所有依赖项。
答案 0 :(得分:0)
你在哪里装你的任务?您需要先使用NPM加载任务,然后才能由Grunt配置和执行。请参阅here。
以下是Grunt网站的一个例子:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'src/<%= pkg.name %>.js',
dest: 'build/<%= pkg.name %>.min.js'
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
// Default task(s).
grunt.registerTask('default', ['uglify']);
};