【发布时间】:2016-05-23 18:42:44
【问题描述】:
我在运行时的大多数 Grunt 任务都面临着类似的问题。请帮助解决这个问题。
在下面添加命令提示符命令,gruntFile.js 和 package.json 文件
grunt 复制 --force
SyntaxError: Unexpected identifier 警告:找不到任务“副本”。使用 --force,继续。
咕噜咕噜的丑化
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"
}
}
【问题讨论】:
-
确保在执行
grunt之前输入npm install
标签: javascript angularjs node.js gruntjs