2014-12-03 49 views
1

我正在運行grunt-contrib-watch 0.6.1,並且在我的gruntfile.js中包含了livereload塊。我還包括livereload.js調用我的html:grunt-contrib-watch livereload 35729 livereload.js無法加載

<script type="text/javascript" src="http://myste.com:35729/livereload.js"></script> 

當我使用我的dev的包膜似乎一切都正常啓動運行服務器。

grunt dev 
Running "env:dev" (env) task 

Running "concurrent:dev" (concurrent) task 

Running "nodemon:dev" (nodemon) task 
[nodemon] v1.2.1 
[nodemon] to restart at any time, enter `rs` 
[nodemon] watching: *.* 
[nodemon] starting `node server.js` 

Application Started on port 3000 

當我做出改變,我可以看到我的ssh控制檯服務器重裝,但livereload.js加載失敗:

當我去港口的位置,它應該是http://myste.com:35729/livereload.js我得到的標準的「網頁不可用」響應。似乎也沒有服務器在http://myste.com:35729/上運行。

我也包括我gruntfile.js是爲了完整性

'use strict'; 

module.exports = function (grunt) { 
    var watchFiles = { 
     serverViews: ['app/views/**/*.*'], 
     serverJS: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js'], 
     clientViews: ['public/views/**/*.html'], 
     clientJS: ['public/js/**/*.js'], 
     clientSASS: 'public/styles/sass/**/*.{scss,sass}', 
     clientCSS: ['public/styles/css/**/*.css'] 
    }; 

    grunt.initConfig({ 
     pkg: grunt.file.readJSON('package.json'), 

     env: { 
      dev: { 
       NODE_ENV: 'development' 
      }, 
      prod: { 
       NODE_ENV: 'production' 
      } 
     }, 
     watch: { 
      serverViews: { 
       files: watchFiles.serverViews, 
       options: { 
        livereload: true 
       } 
      }, 
      serverJS: { 
       files: watchFiles.serverJS, 
       tasks: ['jshint'], 
       options: { 
        livereload: true 
       } 
      }, 
      clientViews: { 
       files: watchFiles.clientViews, 
       options: { 
        livereload: true, 
       } 
      }, 
      clientJS: { 
       files: watchFiles.clientJS, 
       tasks: ['jshint'], 
       options: { 
        livereload: true 
       } 
      }, 
      clientSASS: { 
       files: watchFiles.clientSASS, 
       tasks: ['sass:dev'], 
       options: { 
        livereload: true, 
        spawn: false 
       } 
      }, 
      clientCSS: { 
       files: watchFiles.clientCSS, 
       tasks: ['csslint'], 
       options: { 
        livereload: true 
       } 
      }, 
     }, 

     nodemon: { 
      dev: { 
       script: 'server.js' 
      } 
     }, 

     nodeunit: { 
      dev: { 
       all: ['app/test/**/*_test.js'], 
       options: { 
        reporter: 'tap', 
        reporterOutput: 'tests.tap', 
        reporterOptions: { 
         output: 'outputdir' 
        } 
       } 
      } 
     }, 

     jshint: { 
      dev: { 
       all: { 
        src: watchFiles.clientJS.concat(watchFiles.serverJS), 
        options: { 
         jshintrc: true 
        } 
       } 
      } 
     }, 

     uglify: { 
      prod: { 
       my_target: { 
        files: { 
         'public/js/all.min.js': ['public/js/library/jquery.js', 'public/js/library/modernizr.js', 'public/js/library/selectivizr.js', 'public/js/library/delfin.js'] 
        } 
       } 
      } 
     }, 

     sass: { 
      dev: { 
       options: { 
        style: 'expanded' 
       }, 
       files: { 
        'public/styles/css/style.css': 'public/styles/scss/style.scss' // 'destination': 'source' 
       } 
      } 
     }, 

     cssmin: { 
      prod: { 
       files: { 
        'public/styles/css/style.min.css': 'public/styles/css/style.css' 
       } 
      } 
     }, 

     csslint: { 
      dev: { 
       options: { 
        csslintrc: '.csslintrc', 
       }, 
       all: { 
        src: watchFiles.clientCSS 
       } 
      } 
     }, 

     concurrent: { 
      dev: { 
       target: { 
        tasks: ['nodemon', 'watch'], 
        options: { 
         logConcurrentOutput: true 
        } 
       } 
      } 
     } 
    }); 

    grunt.loadNpmTasks('grunt-contrib-cssmin'); 
    grunt.loadNpmTasks('grunt-contrib-csslint'); 
    grunt.loadNpmTasks('grunt-contrib-jshint'); 
    grunt.loadNpmTasks('grunt-contrib-nodeunit'); 
    grunt.loadNpmTasks('grunt-contrib-sass'); 
    grunt.loadNpmTasks('grunt-contrib-uglify'); 
    grunt.loadNpmTasks('grunt-contrib-watch'); 
    grunt.loadNpmTasks('grunt-express-server'); 
    grunt.loadNpmTasks('grunt-concurrent'); 
    grunt.loadNpmTasks('grunt-nodemon'); 
    grunt.loadNpmTasks('grunt-env'); 

    grunt.registerTask('dev', ['env:dev', 'concurrent', 'nodemon', 'watch', 'jshint', 'nodeunit', 'sass']); 
    grunt.registerTask('prod', ['env:prod', 'cssmin', 'uglify', 'nodemon']); 
}; 
+1

您正在運行'concurent task'包括'watch'和'nodemon'任務和然後再次運行此任務。這可能會導致你的問題。檢查如果你從'grunt dev'聲明中刪除它們會發生什麼 – 2014-12-03 20:21:51

+0

@GlenSwift謝謝你的建議。我試圖從開發聲明中刪除它們,但是然後服務器無法啓動。我也嘗試刪除從開發併發,加載服務器,但livereload訪問仍然失蹤。 – Finglish 2014-12-03 20:42:59

+0

嗯,這是我的併發任務的實例: 併發:{ 任務:[ 'nodemon', '手錶'], 選項:{ logConcurrentOutput:真 } } 我咕嚕運行它,並做不單獨運行watch和nodemon。我不確定這會有幫助,但你可以嘗試嗎?它對我來說非常合適。 – 2014-12-03 21:07:52

回答

2

您嘗試運行nodemonwatch任務的兩倍。首先,當你運行concurrent任務時,第二次當你自稱。

concurrent任務的配置更改爲

concurrent: { 
    tasks: ['nodemon', 'watch'], 
    options: { 
     logConcurrentOutput: true 
    } 
}, 

而且從grunt dev聲明中刪除多餘的任務:

grunt.registerTask('dev', ['env:dev', 'concurrent', 'jshint', 'nodeunit', 'sass']);