Javascript GrunFile.js任务。。。错误
试图让Grunt将我的CSS文件压缩成一个名为production.CSS的文件 以下是命令提示符的输出Javascript GrunFile.js任务。。。错误,javascript,node.js,gruntjs,npm,Javascript,Node.js,Gruntjs,Npm,试图让Grunt将我的CSS文件压缩成一个名为production.CSS的文件 以下是命令提示符的输出 C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test>grunt C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test\Gruntfile.js:2 "name": "AjaxPmodule.exports = function(grunt) { ^ L
C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test>grunt
C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test\Gruntfile.js:2
"name": "AjaxPmodule.exports = function(grunt) {
^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected token :
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test>grunt
C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test\Gruntfile.js:2
"name": "AjaxPmodule.exports = function(grunt) {
^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected token :
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test>
这是我的文件
{
"name": "AjaxPmodule.exports = function(grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
dist: {
src: [
'css/*.css', // All JS in the libs folder
],
dest: 'css/production.css',
}
}
});
// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-concat');
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', ['concat']);
};roject",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-concat": "^0.5.0"
}
}
我正在使用grunt contrib concat来解析我的文件。版本为“^0.5.0”您出于某种原因在文件中添加了一些额外的文本。它应该从module.exports开始,最后还有一些额外的内容 我认为您所做的基本上是将grunt代码粘贴到类似package.json的代码段中:
{
"name": "ajaxProject",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-concat": "^0.5.0"
}
}
试试这个:
module.exports = function(grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
dist: {
src: [
'css/*.css', // All JS in the libs folder
],
dest: 'css/production.css',
}
}
});
// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-concat');
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', ['concat']);
}
很好,更新原因。如上所述,看起来您已经将gruntcode粘贴到类似package.json片段的东西中。