【问题标题】:Grunt-contrib-connect: how to launch the server in a specified browserGrunt-contrib-connect:如何在指定的浏览器中启动服务器
【发布时间】:2014-05-29 14:32:23
【问题描述】:

我对 bower / grunt / yeoman 环境很陌生。我正在尝试自定义由默认 yeoman Webapp 生成器 生成的应用程序。

基本上,当我启动grunt serve 时,默认浏览器将打开并打开 grunt 服务器提供的 url。我想指定应该在哪个浏览器中打开 webapp,但我没有运气。

这些是我的 gruntfile 中连接任务的默认选项(使用 grunt-contrib-connect):

connect: {
        options: {
            port: 9000,
            open: true,
            livereload: 35729,
            // Change this to '0.0.0.0' to access the server from outside
            hostname: 'localhost',
        }

我尝试添加字段appName: 'Firefox',但我认为这不是我想要的。我猜appName 用于指定如何从命令行启动默认浏览器(例如使用open 命令),对吗?

是否可以在 grunt-contrib-connect 中指定浏览器或根本不指定?如果不是,我应该如何完成这项任务?也许使用 grunt-open?

谢谢

【问题讨论】:

    标签: node.js gruntjs grunt-contrib-watch grunt-contrib-connect


    【解决方案1】:

    根据 grunt-contrib-connect 中的this commit ,open 选项似乎从 v0.6.0 开始支持。 但是app生成的webapp generator默认使用v0.5.0。

    所以你需要在package.json升级它。

        "grunt-contrib-connect": "~0.7.1",
    

    然后运行npm install(如果已安装v0.7.1,您可以使用npm list | grep grunt-contrib-connect 仔细检查)并在Gruntfile.js 中添加open 选项。

        connect: {
            ...
            livereload: {
                options: {
                    open: {
                        appName: 'Firefox'
                    },
            ...
    

    这对我有用,所以我希望这对你也有帮助。

    【讨论】:

    • 完美,老实说版本已经是 0.7.1,但我在错误的位置和错误的方式使用了该选项。我错误地将appName 放入connect: { options: {appName: 'Firefox'}} 谢谢
    猜你喜欢
    • 1970-01-01
    • 2014-06-25
    • 1970-01-01
    • 1970-01-01
    • 2014-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-28
    相关资源
    最近更新 更多