我在运行时遇到了大部分Grunt任务的类似问题..请帮忙...
在
下面添加命令提示符命令,gruntFile.js和package.json文件grunt copy --force
SyntaxError:意外的标识符警告:找不到任务“copy”。使用--force,继续。
grunt uglify
SyntaxError:意外的标识符警告:找不到任务“uglify”。使用--force继续。
GruntFile.js
'use strict';
module.exports = function (grunt) {
// https://github.com/sindresorhus/load-grunt-tasks
require('load-grunt-tasks')(grunt);
// http://gruntjs.com/configuring-tasks#grunt-configuration
grunt.initConfig({
/* https://www.npmjs.com/package/grunt-contrib-jshint */
/* http://jshint.com/docs/options/ */
jshint: {
options: {
curly: true,
eqeqeq: true,
eqnull: true,
browser: true,
globals: {
jQuery: true
},
},
user: ['app/js/**/*.js', '!app/js/jQuery.js'],
gruntfile: {
options: {
node: true
},
files: {
src: ['Gruntfile.js']
}
}
},
// https://www.npmjs.com/package/grunt-contrib-clean
clean: {
dist: {
src: ['dist/']
},
},
// https://www.npmjs.com/package/grunt-contrib-copy
copy: {
dist: {
files: [{
expand: true,
cwd: 'app/',
src: ['js/**/*.js',
'**/*.html',
'css/**/*.css',
],
dest: 'dist/'
}]
},
},
// https://www.npmjs.com/package/grunt-contrib-watch
watch: {
livereload: {
files: ['app/**/*.html',
'app/js/**/*.js',
'app/css/**/*.css',
'app/images/**/*.{jpg,gif,svg,jpeg,png}'
],
options: {
livereload: true
}
},
},
uglify: {
combine: {
files: {
'html/js/main.js': ['html/js/one.js']
}
}
}
});
// Tasks to run
// default task > grunt
grunt.registerTask('default', ['connect:app', 'watch']);
// lint js > grunt validate-js
grunt.registerTask('validate-js', ['jshint']);
//publish finished site to /dist directory > grunt publish
grunt.registerTask('publish', ['clean:dist', 'validate.js', 'copy:dist', 'imagemin', 'connect:dist']);
};
的package.json
{
"name": "Udacity-P",
"description": "",
"version": "0.0.1",
"homepage": "",
"author": {
"name": "",
"email": ""
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-connect": "^0.11.2",
"grunt-contrib-copy": "^0.8.1",
"grunt-contrib-imagemin": "^0.9.4",
"grunt-contrib-jshint": "^0.11.3",
"grunt-contrib-watch": "^0.6.1",
"grunt-responsive-images": "^0.1.6",
"load-grunt-tasks": "^3.3.0"
}
}
答案 0 :(得分:0)
从package.json
开始,您尚未下载uglify
任务。
npm install grunt-contrib-uglify --save-dev