2015-08-23 147 views
-1

我有我的咕噜服务任务的问题。它到达express:dev任务时似乎挂起;Grunt Serve - 快速:开发任务卡住

暗战“表示:开发”(快递)任务 启动后台Express服务器 调试器监听端口5858

这在现有项目中,咕噜发球用于正常工作。这个问题昨天开始,当我的Mac电源中断时,在我的脑海里,无论是我还是无意中改变了一些东西,并在苹果机出现故障之前将其破坏,这种威力只是巧合。

有没有人有任何想法?

'use strict'; 


module.exports = function(grunt) { 

    require('load-grunt-tasks')(grunt); 


    var deploySettings = grunt.file.readJSON('config.json'), 
    deploy = deploySettings.production; 
    var useminSettings = [] 


    var appConfig = { 
     app: require('./bower.json').appPath || 'app', 
     dist: 'dist' //require('./bower.json').distPath || 
    }; 

    grunt.initConfig({ 

     mainApp: appConfig, 

     express: { 
      options: { 
      port: process.env.PORT || 9000 
     }, 
     dev: { 
      options: { 
       script: 'app.js', 
       debug: true, 
       node_env: 'development', 
       livereload:true, 
       serverreload: true 
      } 
     }, 
     prod: { 
      options: { 
       script: 'dist/app.js', 
       node_env: 'production' 
      } 
     } 
    }, 

    watch: { 
     bower: { 
      files: ['bower.json'], 
      tasks: ['wiredep'] 
     }, 
     js : { 

      files: ['<%= mainApp.app %>/js/**/*.js'], 
      tasks: ['newer:jshint:all'], 
      options: { 
        livereload: true //'<%= connect.options.livereload %>' 
       } 

      }, 
      gruntfile: { 
       files: ['Gruntfile.js'] 
      }, 
      less: { 
       files: ['<%= mainApp.app %>/css/**/*.less'], 
       tasks: ['less:development'] 
      }, 
      livereload: { 
       options: { 
        livereload : true //'<%= connect.options.livereload %>' 
       }, 
       files: [ 
       '<%= mainApp.app %>/**/*.html', 
      '<%= mainApp.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}' 
      ] 
     }, 
     express: { 
      files: [ 
      'server/**/*.{js,json}' 
      ], 
      tasks: ['less:development','express:dev', 'wait'], 
      options: { 
       livereload: true, 
        nospawn: true //Without this option specified express won't be reloaded 
       } 
      } 
     }, 

     // The actual grunt server settings 
     /* 
     connect: { 
      options: { 
       port: 9000, 
       // Change this to '0.0.0.0' to access the server from outside. 
       hostname: '0.0.0.0', 
       livereload: 35729 
      }, 
      livereload: { 
       options: { 
        open: true, 
        middleware: function (connect) { 
         return [ 
          connect.static('.tmp'), 
          connect().use(
           '/bower_components', 
           connect.static('./bower_components') 
          ), 
          connect.static(appConfig.app) 
         ]; 
        } 
       } 
      } 
     }, 
     */ 


     // Automatically inject Bower components into the app 
     wiredep: { 
      app: { 
       src: ['<%= mainApp.app %>/index.html'] 
       //ignorePath: /\.\.\// 
      } 
     }, 

     // Make sure code styles are up to par and there are no obvious mistakes 
     jshint: { 
      options: { 
       jshintrc: '.jshintrc', 
       reporter: require('jshint-stylish') 
      }, 
      all: { 
       src: [ 
       'Gruntfile.js', 
      '<%= mainApp.app %>/js/{,*/}*.js' 
      ] 
     } 
    }, 

     //compiles our less down 
     less : { 
      development:{ 
       options:{ 
        path: '<%= mainApp.app %>/css/main.less', 
        rootPath: '/css/', 
        relativeUrls: false 
       }, 
       files: { 
        '<%= mainApp.app %>/css/main.css' : '<%= mainApp.app %>/css/main.less' 
       } 
      } 
     }, 

     // Empties folders to start fresh 
     clean: { 
      dist: { 
       files: [{ 
        dot: true, 
        src : [ 
        '.tmp', 
       '<%= mainApp.dist %>/{,*/}*', 
       '<%= mainApp.dist %>/.git*' 
       ] 
      }] 
     }, 
     server: '.tmp' 
    }, 

     // Reads HTML for usemin blocks to enable smart builds that automatically 
     // concat, minify and revision files. Creates configurations in memory so 
     // additional tasks can operate on them 
     useminPrepare: { 
      html: '<%= mainApp.app %>/index.html', 
      options: { 
       dest: '<%= mainApp.dist %>/public', 
       flow: { 
        html: { 
         steps: { 
          js: ['concat', 'uglifyjs'], 
          css: ['cssmin'] 
         }, 
         post: {} 
        } 
       } 

      } 
     }, 

     // Add vendor prefixed styles 
     autoprefixer: { 
      options: { 
       browsers: ['last 1 version'] 
      }, 
      dist: { 
       files: [{ 
        expand: true, 
        cwd: '.tmp/styles/', 
       src: '{,*/}*.css', 
       dest: '<%= mainApp.dist %>/public/styles/' 
      }] 
     } 
    }, 

     // ng-annotate tries to make the code safe for minification automatically 
     // by using the Angular long form for dependency injection. 
     ngAnnotate: { 
      dist: { 
       files: [{ 
        expand: true, 
        cwd: '.tmp/concat/scripts', 
        src: ['*.js'], 
        dest: '.tmp/concat/scripts' 
       }] 
      } 
     }, 

     //copies remaining files to places other tasks can use 
     copy: { 
      dist: { 
       files: [{ 
        expand: true, 
        dot: true, 
        cwd: '<%= mainApp.app %>', 
        dest: '<%= mainApp.dist %>/public', 
        src:[ 
        '*.html', 
       'views/partials/{,*/}*.html', 
      'static/img/{,*/}*.{png,jpg,jpeg,gif,ico,svg}', 
     'css/fonts/{,*/}*.{ttf,woff,eot,otf}' 
     ] 
    }, { 
     expand: true, 
     cwd: '.tmp/images', 
     dest: '<%= mainApp.dist %>/public/images', 
     src: ['generated/*'] 
    }, { 
     expand: true, 
     cwd: 'public/bower_components/bootstrap/dist', 
    src: 'fonts/{,*/}*.{ttf,woff,eot,otf}', 
    dest: '<%= mainApp.dist %>/public' 
}, { 
    expand: true, 
    dest: '<%= mainApp.dist %>', 
    src: [ 
    'app.js', 
    'package.json', 
    'server/**/*' 
    ] 
}] 
}, 
debug: { 
    files: [{ 
     expand: true, 
     dot: true, 
     cwd: '<%= mainApp.app %>', 
     dest: '<%= mainApp.dist %>', 
     src:[ 
     '*.html', 
    'views/partials/{,*/}*.html', 
'js/{,*/}*.js', 
'css/{,*/}*.css', 
'static/img/{,*/}*.{png,jpg,jpeg,gif}', 
'css/fonts/{,*/}*.{ttf,woff,eot,otf}' 
] 
}, { 
    expand: true, 
    cwd: '.tmp/images', 
    dest: '<%= mainApp.dist %>/images', 
    src: ['generated/*'] 
}, { 
    expand: true, 
    cwd: 'public/bower_components/bootstrap/dist', 
src: 'fonts/{,*/}*.{ttf,woff,eot,otf}', 
dest: '<%= mainApp.dist %>' 
}] 
}, 
styles : { 
    expand: true, 
    cwd: '<%= mainApp.app %>/styles', 
    dest: '.tmp/styles', 
src: '{,*/}*.css' 
} 
}, 

     // Run some tasks in parallel to speed up the build process 
     concurrent: { 
      dist:[ 
      'copy:styles' 
      ] 

     }, 

     // Replace Google CDN references 
     cdnify: { 
      dist: { 
       html: ['<%= mainApp.dist %>/public/*.html'] 
      } 
     }, 

     // Renames files for browser caching purposes 
     filerev: { 
      dist: { 
       src: [ 
      '<%= mainApp.dist %>/public/scripts/{,*/}*.js', 
     '<%= mainApp.dist %>/public/styles/{,*/}*.css' 
//   '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}', 
//   '<%= yeoman.dist %>/styles/fonts/*' 
] 
} 
}, 

     // Performs rewrites based on filerev and the useminPrepare configuration 
     usemin: { 
     html: ['<%= mainApp.dist %>/public/{,*/}*.html'], 
    css: ['<%= mainApp.dist %>/public/styles/{,*/}*.css'], 
    options: { 
     assetsDirs: ['<%= mainApp.dist %>/public'] 
    } 
}, 


htmlmin: { 
    dist: { 
     options: { 
      collapseWhitespace: true, 
      conservativeCollapse: true, 
      collapseBooleanAttributes: true, 
      removeCommentsFromCDATA: true, 
      removeOptionalTags: true 
     }, 
     files: [{ 
      expand: true, 
      cwd: '<%= mainApp.dist %>', 
     src: ['*.html', 'views/partials{,*/}*.html'], 
     dest: '<%= mainApp.dist %>/public' 
    }] 
} 
}, 

imagemin : { 
      dynamic: {       // Another target 
       files: [{ 
        expand: true,     // Enable dynamic expansion 
        cwd: '<%= mainApp.dist %>/public/static', // Src matches are relative to this path 
        src: ['**/*.{png,jpg,gif}'], // Actual patterns to match 
        dest: '<%= mainApp.dist %>/public/static'     // Destination path prefix 
       }] 
      } 

     }, 


}); 



    // Used for delaying livereload until after server has restarted 
    grunt.registerTask('wait', function() { 
     grunt.log.ok('Waiting for server reload...'); 

     var done = this.async(); 

     setTimeout(function() { 
      grunt.log.writeln('Done waiting!'); 
      done(); 
     }, 1500); 
    }); 

    grunt.registerTask('express-keepalive', 'Keep grunt running', function() { 
     this.async(); 
    }); 



    grunt.registerTask('serve', 'Compile then start a connect web server', function(){ 



    grunt.task.run([ 
     'clean:server', 
     'less:development', 
     'wiredep', 
      // 'concurrent:server', 
      //'connect:livereload', 
      'express:dev', 
      //'express-keepalive', 
      'wait', 
      'watch' 

      ]); 

}); 



    grunt.registerTask('build', function(){ 

      grunt.task.run([ 
       'clean:dist', 
       'less:development', 
       'wiredep', 
       'useminPrepare', 
       'concurrent:dist', 
       'copy:styles', 
       'autoprefixer', 
       'concat', 
       'ngAnnotate', 
       'copy:dist', 
       'cdnify', 
       'cssmin', 
       'uglify', 
       'filerev', 
       'usemin', 
       'htmlmin', 
       'express:dev' 
       ]); 

    }); 




grunt.registerTask('debug', [ 
    'clean:dist', 
    'less:development', 
    'wiredep', 
    'copy:debug' 
    ]); 






grunt.registerTask('default', [ 
    'serve' 
    ]); 


}; 
+1

发布Gruntfile以提供更多信息。 – lifeisfoo

回答

1

我找到了解决方案,通过恢复到以前的git并手动添加更改。

不知何故,这是节点调度程序的问题。我正在使用dayOfWeek = 7的重复规则来安排任务。这在grunt serve中产生错误,与发生的grunt文件无关。

我改变了这个dayOfWeek = 0,它很好。