[英]Grunt tasks stuck in endless loop
Working on putting together a base Gruntfile.js
for some upcoming projects. 正在为一些即将开展的项目组建一个基础Gruntfile.js
。 Starting in on a new computer so everything has been a fresh build. 从一台新电脑开始,所以一切都是新的。 Installed Node and NPM using Homebrew, and then installed Grunt globally, as well as in my local directory. 使用Homebrew安装Node和NPM,然后在全局和本地目录中安装Grunt。
Here is my package.json
: 这是我的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"
}
}
And here is my Gruntfile.js
: 这是我的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']);
};
The problem that I am seeing is that with multiple tasks, here specifically with wiredep
and concat
, the task gets stuck in a loop and never ends. 我看到的问题是,对于多个任务,特别是使用wiredep
和concat
,任务陷入循环并且永远不会结束。 Running grunt concat
with verbose outputs like this: 像这样使用详细输出运行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
Where Running "concat" task
will continue to print until I stop it. Running "concat" task
将继续打印,直到我停止它。 As I am seeing this with multiple plugins and tasks this might be a problem with my installation of NPM or Grunt, but I'm having a very hard time debugging this. 正如我在多个插件和任务中看到的那样,这可能是我安装NPM或Grunt时遇到的问题,但是我很难调试这个。 If anyone has run into this before, please let me know what helped! 如果有人之前碰到过这个,请告诉我有什么帮助!
Thanks! 谢谢!
Edit: in response to Alireza Ahmadi's comment, here is my file structure: 编辑:回应Alireza Ahmadi的评论,这是我的文件结构:
.
|
|_ app/
|_ assets/
|_ javascript/
|_ stylesheets/
|_ views/
|
|_ build/
|_stylesheets/
|_javascripts/
|
|_ vendor/
|_ bower.json
|_ Gruntfile.js
|_ package.json
In the last 2 lines of your Gruntfile.js
you have redeclared the concat
and wiredep
tasks and when grunt tries to run your code, It stuck in an endless loop because concat refers to an undefined concat task, So you should remove these lines: 在你的Gruntfile.js
的最后两行中,你重新声明了concat
和wiredep
任务,当grunt尝试运行你的代码时,它陷入无限循环,因为concat引用了一个未定义的concat任务,所以你应该删除这些行:
grunt.registerTask('concat', ['concat']);
grunt.registerTask('wiredep', ['wiredep']);
In general, When you define a task named foobar
with grunt.initConfig
, It's defined and does not need to registered using registerTask
and it can be accessible by grunt foobar
command. 通常,当您使用grunt.initConfig
定义名为foobar
的任务时,它已定义并且不需要使用registerTask
进行registerTask
,并且可以通过grunt foobar
命令访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.