Javascript Grunt返回所有任务的错误
Grunt返回所有任务的错误“未找到目标”或“未找到任务”。 另外,grunt--help不会显示某些可用的任务,例如“构建”和“测试”任务 此配置以前似乎工作正常。但它没有改变(git确保了这一点) 怎么了 这是我的Grunfile.js:Javascript Grunt返回所有任务的错误,javascript,gruntjs,Javascript,Gruntjs,Grunt返回所有任务的错误“未找到目标”或“未找到任务”。 另外,grunt--help不会显示某些可用的任务,例如“构建”和“测试”任务 此配置以前似乎工作正常。但它没有改变(git确保了这一点) 怎么了 这是我的Grunfile.js: module.exports = function(grunt) { require('time-grunt')(grunt); require('load-grunt-tasks')(grunt); grunt.initConfig({
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'
]);
};
使用npm安装的所有依赖项。您在哪里加载任务?在Grunt配置和执行任务之前,需要使用NPM加载任务。看 下面是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']);
};
module.exports=函数(grunt){
//项目配置。
grunt.initConfig({
pkg:grunt.file.readJSON('package.json'),
丑陋的:{
选项:{
横幅:'/*!*/\n'
},
建造:{
src:'src/.js',
dest:'build/.min.js'
}
}
});
//加载提供“丑”任务的插件。
grunt.loadNpmTasks(“grunt-contrib-uglify”);
//默认任务。
registerTask('default',['uglify']);
};
require('load-grunt-tasks')(grunt)加载mypackage.json中列出的所有任务。@WlodzislavK。嗯,您是否运行了NPM安装?是否确实存在模块?…添加--verbose
标志是否提供了指向问题根源的任何其他详细信息?
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']);
};