Grunt Serve - 表达:开发任务卡住

时间:2015-08-23 08:35:35

标签: node.js express gruntjs

我的grunt服务任务有问题。当它到达express:dev task;

时似乎挂起了

跑步"表达:dev" (表达)任务 启动后台Express服务器 调试器侦听端口5858

这是一个现有项目,其中grunt服务用于工作正常。这个问题从昨天开始,当时我的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 个答案:

答案 0 :(得分:1)

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

不知何故,这是node-scheduler的一个问题。我正在使用dayOfWeek = 7的重复规则来安排任务。这在grunt服务器中产生错误,与grunt文件无关。

我将此更改为dayOfWeek = 0并且没问题。