2014-11-27 3 views
4

gruntfile을 설정하여 grunt connect npm 모듈을 사용하려고합니다. grunt clean server 명령으로 내 서버를 시작하려고 할 때 문제가 있습니다. 다음 줄에 오류가 있습니다.그란트 연결이 오류로 시작하지 않음 "루트 경로가 문자열이어야합니다"

Warning: root path must be a string Use --force to continue. 

어떤 구성이 엉망이되어 다른 눈을 사용할 수 있는지 잘 모르겠습니다. 문제는 middlewareundefined 것을처럼

Verifying property connect.dev exists in config...OK 
File: [no files] 
Options: protocol="http", port="9000", hostname="*", base="BUILD", directory=null, keepalive=false, debug=false, livereload=false, open=false, useAvailablePort=false, onCreateServer=null, middleware=undefined 

그것은 나에게 보인다하지만 난 아무 생각도 이유가 없다 : 나는 다음 줄을 얻을 --verbose 플래그를 사용하면

/* global module, conf */ 
var modRewrite = require('connect-modrewrite'); 
var mountFolder = function(connect, dir) { 
    return connect.static(require('path').resolve(dir)); 
}; 
module.exports = function(grunt) { 

    grunt.initConfig({ 
     copy: { 
      base: { 
       files: [ 
        {src: "index.html", dest: "BUILD/index.html"}, 
        {expand: true, src: "app/**", dest: "BUILD/"}, 
        {expand: true, src: "assets/**", dest: "BUILD/"} 
       ] 
      } 
     }, 

     connect: { 
      proxies: [ 
       { 
        context: "/wwff", 
        host: "localhost", 
        port: "8080" 
       } 
      ], 

      /** 
      * Task defines a server at 9000, 
      * watching the BUILD directory 
      */ 
      dev: { 
       options: { 
        port: "9000", 
        hostname: '*', 
        base: "BUILD", 
        middleware: function(connect, options) { 
         var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest; 

         return [ 
          // include the proxy first 
          proxySnippet, 
          modRewrite([ 
           '!\\.html|\\.js|\\.swf|\\.json|\\.xml|\\.css|\\.png|\\.jpg|\\.gif|\\.ico|\\.aff|\\.msi|\\.zip|\\.dic$ /index.html [L]' 
          ]), 
          // serve static files 
          connect.static(options.base), 
          // make empty directories browsable 
          connect.directory(options.base) 
         ]; 
        } 
       } 
      } 
     }, 

     /* 
     * This task watches the application and asset directories and 
     * deploys any changes to the dev server 
     */ 
     watch: { 
      static: { 
       files: [ "app/**/*.js", "app/**/*.html"], 
       tasks: ["build"] 
      } 
     }, 

     clean: { 
      build: ["BUILD/"], 
      temp: ["tmp"] 
     } 
    }); 

    grunt.loadNpmTasks('grunt-contrib-copy'); 
    grunt.loadNpmTasks('grunt-contrib-connect'); 
    grunt.loadNpmTasks('grunt-contrib-watch'); 
    grunt.loadNpmTasks('grunt-connect-proxy'); 
    grunt.loadNpmTasks('grunt-contrib-clean'); 

    /* 
    * Main BUILD Task 
    */ 
    grunt.registerTask("build", "Copies app and asset files to the BUILD directory.", function() { 
     grunt.task.run("copy:base"); 
    }); 

    grunt.registerTask("server", "Stand up a node server for development.", function() { 
     grunt.task.run(["build", "configureProxies:dev", "connect:dev", "watch"]); 
    }); 

    grunt.event.on('watch', function(action, filepath, target) { 
     grunt.log.writeln(target + ': ' + filepath + ' has ' + action); 
    }); 

}; 

: 이것은 내 Gruntfile입니다 그것은.

도움을 주시면 감사하겠습니다.

답변

4

글쎄, 어떻게 이해할 수는 없지만 내 middleware 함수의 내 options.base 함수가 첫 번째 값이 BUILD 인 배열이 된 것 같습니다.

그래서 내 middleware 기능에 대한 다음 코드는 작동합니다

middleware: function(connect, options) { 
    var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest; 

    return [ 
     // include the proxy first 
     proxySnippet, 
     modRewrite(['!\\.html|\\.js|\\.swf|\\.json|\\.xml|\\.css|\\.png|\\.jpg|\\.gif|\\.ico|\\.aff|\\.msi|\\.zip|\\.dic$ /index.html [L]']), 
     // serve static files 
     connect.static(options.base[0]), 
     // make empty directories browsable 
     connect.directory(options.base[0]) 
    ]; 
} 

위의 조각의 중요한 부분은 내 options.base 지금 options.base[0] 것입니다. 왜 그런지에 대한 설명을 누군가가 가지고 있다면, 그것은 매우 감사 할 것입니다.

0

그 이유는 options.base가 배열이기 때문입니다. options.base [0]은 배열의 첫 번째 항목 (이 경우에만 해당) (루트 경로를 나타내는 문자열)을 나타냅니다.

1

게임에 늦었지만 최신 버전의 grunt-connect base은 항상 배열입니다. 당신은 너무 같은 두 버전의 미들웨어 호환되도록 할 수 있습니다

middleware: function (connect, options) { 
    // Older versions of grunt-connect. 
    if (!Array.isArray(options.base)) { 
     options.base = [options.base]; 
    } 

    var middlewares = [ 
     require('connect-livereload')() 
    ]; 

    // Serve static files. 
    options.base.forEach(function(base) { 
     middlewares.push(connect.static(base)); 
    }); 

    return middlewares; 
} 

을 가진 예를 들어 꿀꿀 - 연결 - 프록시이 단지 options.base[0]에서 1 루를 장착보다 더 https://github.com/drewzboto/grunt-connect-proxy

에서 문서를 참조하십시오.