2016-08-30 61 views
0

我使用:https://github.com/gruntjs/grunt-contrib-connect運行咕嚕-的contrib-連接運行,但不工作

"grunt-contrib-connect": "^1.0.2", 

後:咕嚕連接

Running "connect:server" (connect) task 
Started connect web server on http://localhost:8000 

Done. 

enter image description here

所以,當我在瀏覽器中查看:localhost:8000,不會打開任何東西。

有人可以幫忙嗎?

gruntfile pastenbin:http://pastebin.com/nL771d5j

Gruntfile.js

module.exports = function (grunt) { 
    var config = {}; 

    //setup the configuration object 
    var jshint; 

    //all tasks that must be loaded. 
    var tasks = [ 
      ,'grunt-contrib-watch' 
      ,'grunt-contrib-concat' 
      ,'grunt-contrib-sass' 
      ,'grunt-contrib-connect' 
    ]; 

       //src =============================== 
       var src; 
       config.src = src = { 
        sassMain  : 'scss/main.scss', 
        distFolder  : 'public/stylesheets/dist.css', 
        devFolder  : 'public/stylesheets/dev.css', 
        sassFolder  : 'scss/**/*.scss', 
        serverPort: 9000, 
        serverHost: '0.0.0.0' 
       }; 


       //Concat =============================== 

       var concat 
       config.concat = concat = {}; 

       concat.dev = { 
        files: { 
         "public/myapp.development.js": [ 
          "with-bootstrap/public/js/vendor" 
          ,"with-bootstrap/public/js/**/*.js" 
         ] 
        } 
       }; 

       //Watch =============================== 
       config.watch = { 
        scripts: { 
         files: ["<%= src.sassFolder %>"] 
         ,tasks: ["sass:dist"] 
        } 
       } 

       //Sass =============================== 
       var sass; 
       config.sass = sass = {}; 

        //distribution 
         sass.dist = { 
          options: { 
           style: "compressed", 
           noCache: true, 
           sourcemap: 'none', 
           update:true 
          } 
          , files: { 
           "<%= src.distFolder %>" : "<%= src.sassMain %>" 
          } 
         }; 

        //development env. 
         sass.dev = { 
          options: { 
           style: "expanded", 
           lineNumber: true, 
          } 
          , files: { 
           "<%= src.devFolder %>" : "<%= src.sassMain %>" 
          } 
         }; 


        //grunt serve =============================== 
        config.connect = { 
         server: { 
          options: { 
          port: 8000, 
          base: { 
           path: 'SITE', 
           options: { 
           index: 'index.html', 
           maxAge: 300000 
           } 
          } 
          } 
         } 
        }; 


    //Register custom tasks =============================== 
    grunt.registerTask('default',['dev']); 
    grunt.registerTask('dev', ['concat:dev','sass:dev']); 
    grunt.registerTask('dist',['concat:dev','sass:dist']); 



    //General setup =============================== 
    grunt.initConfig(config); 
    tasks.forEach(grunt.loadNpmTasks); 

}; 

回答

0

如果你本身運行grunt-contrib-connect插件,你需要的屬性keepalive設置爲真正在你的呼嚕聲config:

config.connect = { 
    server: { 
     options: { 
      port: 8000, 
      keepAlive: true, 
      base: { 
       path: 'SITE', 
       options: { 
        index: 'index.html', 
        maxAge: 300000 
       } 
      } 
     } 
    } 
}; 

值得注意的如果要將連接配置用作任務鏈的一部分,則需要將keepAlive設置爲false,否則connect任務之後的任務將無法運行。您也可以通過使用keepAlive選項將其與watch任務不配對運行來保持connect的運行。