Gruntjs 如何在约曼更改Livereload的自动打开页面?

Gruntjs 如何在约曼更改Livereload的自动打开页面?,gruntjs,yeoman,livereload,Gruntjs,Yeoman,Livereload,当我使用yeoman并运行grunt server时,livereload将自动打开一个网页127.0.0.1:9000。 但是我使用nginx代理127.0.0.1:9000访问foo.com,所以我希望自动打开foo.com而不是127.0.0.1:9000 我检查了Gruntfile.js并找到了配置,但似乎无法更改主机名: connect: { options: { port: 9000, // Change this to '0.0.0.0' to access t

当我使用yeoman并运行
grunt server
时,livereload将自动打开一个网页127.0.0.1:9000。 但是我使用nginx代理127.0.0.1:9000访问foo.com,所以我希望自动打开foo.com而不是127.0.0.1:9000

我检查了
Gruntfile.js
并找到了配置,但似乎无法更改主机名:

connect: {
  options: {
    port: 9000,
    // Change this to '0.0.0.0' to access the server from outside.
    hostname: 'localhost',
    livereload: 35729
  },
  livereload: {
    options: {
      open: true,
      base: [
        '.tmp',
        '<%= yeoman.app %>'
      ]
    }
  },
  ...
package.json:

{
  "name": "foo",
  "version": "0.0.0",
  "dependencies": {},
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-autoprefixer": "~0.4.0",
    "grunt-concurrent": "~0.4.1",
    "grunt-contrib-clean": "~0.5.0",
    "grunt-contrib-coffee": "~0.7.0",
    "grunt-contrib-compass": "~0.6.0",
    "grunt-contrib-concat": "~0.3.0",
    "grunt-contrib-connect": "~0.5.0",
    "grunt-contrib-copy": "~0.4.1",
    "grunt-contrib-cssmin": "~0.7.0",
    "grunt-contrib-htmlmin": "~0.1.3",
    "grunt-contrib-imagemin": "~0.3.0",
    "grunt-contrib-jshint": "~0.7.1",
    "grunt-contrib-uglify": "~0.2.0",
    "grunt-contrib-watch": "~0.5.2",
    "grunt-google-cdn": "~0.2.0",
    "grunt-ngmin": "~0.0.2",
    "grunt-rev": "~0.1.0",
    "grunt-svgmin": "~0.2.0",
    "grunt-usemin": "~2.0.0",
    "jshint-stylish": "~0.1.3",
    "load-grunt-tasks": "~0.2.0",
    "time-grunt": "~0.2.0",
    "karma-ng-scenario": "~0.1.0",
    "grunt-karma": "~0.6.2",
    "karma-script-launcher": "~0.1.0",
    "karma-chrome-launcher": "~0.1.0",
    "karma-firefox-launcher": "~0.1.0",
    "karma-html2js-preprocessor": "~0.1.0",
    "karma-jasmine": "~0.1.3",
    "karma-requirejs": "~0.1.0",
    "karma-coffee-preprocessor": "~0.1.0",
    "karma-phantomjs-launcher": "~0.1.0",
    "karma": "~0.10.4",
    "karma-ng-html2js-preprocessor": "~0.1.0"
  },
  "engines": {
    "node": ">=0.8.0"
  },
  "scripts": {
    "test": "grunt test"
  }
}

只需编辑
open:server
target:

默认情况下,您将获得:

open: {
  server: {
    url: 'http://localhost:<%= connect.options.port %>'
  }
},
打开:{
服务器:{
网址:'http://localhost:'
}
},

休闲对我来说很有效:

 open: 'http://localhost:<%= connect.options.port %>',
open:'http://localhost:',

只需尝试在中更改
端口即可

connect: {
  options: {
    port: 9000,
    // Change this to '0.0.0.0' to access the server from outside.
    hostname: 'localhost',
    livereload: 35729
  },
我使用了8999端口而不是9000端口,它很简单


编辑:我忘了提到我在运行
grunt服务器
时收到与您相同的错误。我使用的是Windows 7。

当前版本的grunt contrib connect(0.7.1)的当前看似正确的配置是设置
选项。打开
变量

connect: {
  livereload: {
    options: {
      open: {
        target: 'http://foo.com'
      }
    }
  }
}


但在这样做的时候,我遇到了这样一个问题:代码更改会被拾取,但不再触发浏览器刷新。查看我最近的问题:

当我更新
open:true
时,页面仍然不会自动打开。嗯?只需更改
url:'http://localhost:“
to
url:”http://foo.com“
…是的,我更改了它,但没有弹出页面。请提供您的Grunfile。我添加了文件详细信息,我只是由yeoman生成的,没有做太多更改。可能是open.server功能不存在?如果成功的话?没错,新版本似乎解决了这个问题。我已经完成了那个项目,还是谢谢你。
connect: {
  livereload: {
    options: {
      open: {
        target: 'http://foo.com'
      }
    }
  }
}