2014-07-21 101 views
0

我一直在盯着我的grunt配置幾個小時了,似乎無法啓動和運行。Grunt - 讓livereload啓動並運行服務器

我的文件正在建設中,我期待他們(除了把手之外基本上就在他們所在的位置),但我真的很努力讓自動更新服務器啓動並運行。無法完全啓動並運行。

如果有人能指出我的方向是正確的,那將是一個巨大的幫助!

module.exports = function(grunt) { 

    grunt.initConfig({ 

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

     sass: { 
      files: { 
       'assets/css/style.css' : 'assets/css/*.scss' 
      }  
     }, 
     assemble: { 
      options: { 
       flatten: true, 
       assets: 'assets', 
       layout: 'templates/layouts/main.hbs' 
      }, 
      pages: { 
       src: ['templates/*.hbs'], 
       dest: '.' 
      } 
     }, 
     watch: { 
      all: { 
       files: '**/*.hbs', 
       tasks: ['assemble'], 
       options: { 
        livereload: true, 
       } 
      }, 
      css: { 
       files: 'assets/css/*.scss', 
       tasks: ['sass'] 
      }, 
      scripts: { 
       files: 'assets/js/*.js', 
      }, 
      livereload: { 
       options : { livereload: true }, 
       files: ['/'] 
      } 
     }, 
     connect: { 
      options: { 
       port: 9001, 
       livereload: 35729, 
       hostname: '0.0.0.0', 
       keepalive: true, 
       open: true 
      } 
     } 
    }); 

    grunt.loadNpmTasks('assemble'); 
    grunt.loadNpmTasks('grunt-contrib-sass'); 
    grunt.loadNpmTasks('grunt-contrib-watch'); 
    grunt.loadNpmTasks('grunt-contrib-connect'); 
    grunt.loadNpmTasks('grunt-open'); 

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

那麼你下載LiveReload或安裝Chrome擴展? – Simon

+0

安裝了Chrome擴展。我已經與其他我沒有設置的grunt構建一起工作,但這是我自己從頭開始編寫的第一個grunt歸檔。 – greypiglet

+0

[我有一個使用livereload的回購](https://github.com/andywillis/EVL) - 歡迎您來看看它。它使用'load-grunt-config'將配置文件拆分成小塊(在grunt文件夾中);你應該看的文件是'Gruntfile.js','grunt/connect.js'和'grunt/watch.js'。您還需要節點模塊'connect-livereload'和'grunt-config-connect'。花了我很多時間想弄清楚如何把它放在一起,所以我明白你的痛苦。 – Andy

回答

0

這是我設法在朋友的幫助下工作的 - 使用了一些過時的模塊。希望對某人有用!

module.exports =功能(咕嚕){

grunt.initConfig({ 
    sass: { 
     all: { 
      files: { 
       'assets/css/style.css' : 'assets/css/main.scss' 
      } 
     } 
    }, 
    assemble: { 
     options: { 
      flatten: true, 
      assets: 'assets', 
      layout: 'templates/layouts/main.hbs' 
     }, 
     pages: { 
      src: ['templates/*.hbs'], 
      dest: '.' 
     } 
    }, 
    watch: { 
     assemble: { 
      files: 'templates/**/*.hbs', 
      tasks: ['assemble'] 
     }, 
     sass: { 
      files: 'assets/css/*.scss', 
      tasks: ['sass'] 
     }, 
     css: { 
      files:['assets/css/*.css'] 
     }, 
     scripts: { 
      files: 'assets/js/*.js', 
     }, 
     livereload: { 
      options : { livereload: true }, 
      files: ['*.html','assets/css/*.css','assets/js/*.js'] 
     } 
    }, 
    connect: { 
     options: { 
      port: 9001, 
      livereload: true, 
      hostname: '0.0.0.0' 
     }, 
     livereload: { 
      options: { 
       open: true, 
       base: ['.'] 
      } 
     } 
    } 
}); 

grunt.loadNpmTasks('assemble'); 
grunt.loadNpmTasks('grunt-contrib-sass'); 
grunt.loadNpmTasks('grunt-contrib-watch'); 
grunt.loadNpmTasks('grunt-contrib-connect'); 

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

}