Grunt 任务陷入无限循环
Grunt tasks stuck in endless loop
正在为一些即将开展的项目构建基础 Gruntfile.js
。从一台新电脑开始,一切都是全新的。使用 Homebrew 安装了 Node 和 NPM,然后在全局以及我的本地目录中安装了 G运行t。
这是我的 package.json
:
{
"name": "timespent-prototype",
"version": "0.1.0",
"devDependencies": {
"assemble": "0.4.37",
"bower": "^1.4.1",
"grunt": "^0.4.5",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-sass": "^0.9.2",
"grunt-contrib-watch": "^0.6.1",
"grunt-newer": "^1.1.0",
"grunt-wiredep": "^2.0.0"
}
}
这是我的 Gruntfile.js
:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
vendor: {
src: ['vendor/**/*.min.js'],
dest: 'build/javascripts/library.js',
}
},
// Takes your scss files and compiles them to css
sass: {
dist: {
options: {
style: 'expanded'
},
files: {
'build/stylesheets/application.css': 'app/stylesheets/application/index.scss'
}
}
},
// Assembles your templates into HTML files
assemble: {
options: {
layoutdir: 'app/views/layouts/',
partials: ['app/views/partials/*.hbs'],
flatten: true,
expand: true
},
pages: {
src: ['app/views/**/*.hbs','!app/views/layouts/*.hbs','!app/views/partials/*.hbs'],
dest: 'build/'
}
},
wiredep: {
task: {
src: ['app/views/layouts/*.hbs']
}
},
// Watches for file changes, runs the default task
watch: {
files: ['app/**/*'],
tasks: ['default'],
options: {
// Start another live reload server on port 1337
livereload: 1337,
}
}
});
// Load the plugins
grunt.loadNpmTasks('assemble');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-newer');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-wiredep');
// Register the tasks
grunt.registerTask('default', ['sass','assemble']);
grunt.registerTask('watch', ['watch']);
grunt.registerTask('concat', ['concat']);
grunt.registerTask('wiredep', ['wiredep']);
};
我看到的问题是,对于多个任务,这里特别是 wiredep
和 concat
,任务陷入循环,永远不会结束。 运行 grunt concat
详细输出如下:
Registering "grunt-contrib-concat" local Npm module tasks.
Reading /Users/jacksonlynch/projects/timespent-prototype/node_modules/grunt-contrib-concat/package.json...OK
Parsing /Users/jacksonlynch/projects/timespent-prototype/node_modules/grunt-contrib-concat/package.json...OK
Loading "concat.js" tasks...OK
+ concat
Running tasks: concat
Running "concat" task
Running "concat" task
Running "concat" task
Running "concat" task
Running "concat" task
Running "concat" task
其中 Running "concat" task
将继续打印直到我停止它。正如我在多个插件和任务中看到的那样,这可能是我安装 NPM 或 G运行t 的问题,但我很难调试它。如果有人 运行 以前参与过这个,请告诉我有什么帮助!
谢谢!
编辑:为回应 Alireza Ahmadi 的评论,这是我的文件结构:
.
|
|_ app/
|_ assets/
|_ javascript/
|_ stylesheets/
|_ views/
|
|_ build/
|_stylesheets/
|_javascripts/
|
|_ vendor/
|_ bower.json
|_ Gruntfile.js
|_ package.json
在您 Gruntfile.js
的最后两行中,您重新声明了 concat
和 wiredep
任务,当 g运行t 尝试 运行 您的代码,它陷入了无限循环,因为 concat 引用了一个未定义的 concat 任务,所以你应该删除这些行:
grunt.registerTask('concat', ['concat']);
grunt.registerTask('wiredep', ['wiredep']);
一般来说,当你用grunt.initConfig
定义一个名为foobar
的任务时,它被定义并且不需要使用registerTask
注册并且可以通过[=17=访问]命令。
正在为一些即将开展的项目构建基础 Gruntfile.js
。从一台新电脑开始,一切都是全新的。使用 Homebrew 安装了 Node 和 NPM,然后在全局以及我的本地目录中安装了 G运行t。
这是我的 package.json
:
{
"name": "timespent-prototype",
"version": "0.1.0",
"devDependencies": {
"assemble": "0.4.37",
"bower": "^1.4.1",
"grunt": "^0.4.5",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-sass": "^0.9.2",
"grunt-contrib-watch": "^0.6.1",
"grunt-newer": "^1.1.0",
"grunt-wiredep": "^2.0.0"
}
}
这是我的 Gruntfile.js
:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
vendor: {
src: ['vendor/**/*.min.js'],
dest: 'build/javascripts/library.js',
}
},
// Takes your scss files and compiles them to css
sass: {
dist: {
options: {
style: 'expanded'
},
files: {
'build/stylesheets/application.css': 'app/stylesheets/application/index.scss'
}
}
},
// Assembles your templates into HTML files
assemble: {
options: {
layoutdir: 'app/views/layouts/',
partials: ['app/views/partials/*.hbs'],
flatten: true,
expand: true
},
pages: {
src: ['app/views/**/*.hbs','!app/views/layouts/*.hbs','!app/views/partials/*.hbs'],
dest: 'build/'
}
},
wiredep: {
task: {
src: ['app/views/layouts/*.hbs']
}
},
// Watches for file changes, runs the default task
watch: {
files: ['app/**/*'],
tasks: ['default'],
options: {
// Start another live reload server on port 1337
livereload: 1337,
}
}
});
// Load the plugins
grunt.loadNpmTasks('assemble');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-newer');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-wiredep');
// Register the tasks
grunt.registerTask('default', ['sass','assemble']);
grunt.registerTask('watch', ['watch']);
grunt.registerTask('concat', ['concat']);
grunt.registerTask('wiredep', ['wiredep']);
};
我看到的问题是,对于多个任务,这里特别是 wiredep
和 concat
,任务陷入循环,永远不会结束。 运行 grunt concat
详细输出如下:
Registering "grunt-contrib-concat" local Npm module tasks.
Reading /Users/jacksonlynch/projects/timespent-prototype/node_modules/grunt-contrib-concat/package.json...OK
Parsing /Users/jacksonlynch/projects/timespent-prototype/node_modules/grunt-contrib-concat/package.json...OK
Loading "concat.js" tasks...OK
+ concat
Running tasks: concat
Running "concat" task
Running "concat" task
Running "concat" task
Running "concat" task
Running "concat" task
Running "concat" task
其中 Running "concat" task
将继续打印直到我停止它。正如我在多个插件和任务中看到的那样,这可能是我安装 NPM 或 G运行t 的问题,但我很难调试它。如果有人 运行 以前参与过这个,请告诉我有什么帮助!
谢谢!
编辑:为回应 Alireza Ahmadi 的评论,这是我的文件结构:
.
|
|_ app/
|_ assets/
|_ javascript/
|_ stylesheets/
|_ views/
|
|_ build/
|_stylesheets/
|_javascripts/
|
|_ vendor/
|_ bower.json
|_ Gruntfile.js
|_ package.json
在您 Gruntfile.js
的最后两行中,您重新声明了 concat
和 wiredep
任务,当 g运行t 尝试 运行 您的代码,它陷入了无限循环,因为 concat 引用了一个未定义的 concat 任务,所以你应该删除这些行:
grunt.registerTask('concat', ['concat']);
grunt.registerTask('wiredep', ['wiredep']);
一般来说,当你用grunt.initConfig
定义一个名为foobar
的任务时,它被定义并且不需要使用registerTask
注册并且可以通过[=17=访问]命令。