2014-09-24 43 views
0

我無法實時重新加載運行。 Grunt沒有報告任何問題。網絡模型在MAMP端口8888上運行,不確定這些信息對於解決這個問題是否重要。使用Gruntjs實時重新加載源代碼

的CSS資源並不

<link rel="stylesheet" href="//localhost:1111/style/style.css"> 

加載這裏是我的Gruntjs.file

module.exports = function(grunt) { 
    grunt.initConfig({ 
     less: { 
      development: { 
       options: { 
        paths: ["style"], 
        compress: true, 
        yuicompress: true, 
        optimization: 2 
       }, 
       files: { 
        "style/style.css": "source/style/style.less" 
       } 
      } 
     }, 
     watch: { 
      less: { 
       files: "source/style/*", 
       tasks: ["less"], 
       options: { 
        nospawn: true 
       } 
      }, 
      css: { 
       files: ['style/style.css'], 
       options: { 
        livereload: 1111 
       } 
      } 
     } 
    }); 
    grunt.loadNpmTasks('grunt-contrib-less'); 
    grunt.loadNpmTasks('grunt-contrib-watch'); 

    grunt.registerTask('default', ['watch']); 
}; 

我如何檢查是否重載服務運行是否正常?

你能幫我嗎? 謝謝

+0

你爲什麼在看css?你可能也想更新你看任務少到'['less:development']' – DavidT 2014-09-24 15:48:40

+0

你把[相應的腳本](https://github.com/gruntjs/grunt-contrib-watch/blob/master /docs/watch-examples.md#enabling-live-reload-in-your-html)到你的文件中?雖然我不確定它是否應該與MAMP服務器一起工作。 – 2014-09-24 17:09:33

+0

我使它工作(請參閱我的答案),但它並不總是重新加載頁面。我生氣了。 :( – tomexx 2014-09-24 18:45:49

回答

0

我找到了一個解決方案。我下載了Chrome LiveReload擴展,現在一切正常。 Gruntfile.js看起來像這樣:

module.exports = function(grunt) { 
    grunt.initConfig({ 
     less: { 
      development: { 
       options: { 
        paths: ["style"], 
        compress: true, 
        yuicompress: true, 
        optimization: 2 
       }, 
       files: { 
        "style/style.css": "source/style/style.less" 
       } 
      } 
     }, 
     watch: { 
      less: { 
       files: "source/style/*", 
       tasks: ["less"], 
       options: { 
        nospawn: true 
       } 
      }, 
      css: { 
       files: ['style/style.css'], 
       options: { 
        livereload: true 
       } 
      } 
     } 
    }); 
    grunt.loadNpmTasks('grunt-contrib-less'); 
    grunt.loadNpmTasks('grunt-contrib-watch'); 

    grunt.registerTask('default', ['watch']); 
}; 
相關問題