在angular2快速入门指南中使用lite-server打开非默认浏览器 [英] Opening non-default browser with lite-server in angular2 quick start guide

查看:209
本文介绍了在angular2快速入门指南中使用lite-server打开非默认浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循 Angular 2快速入门指南的TypeScript版本,我想知道是否是可能,如果可以,如何配置lite服务器以启动默认浏览器以外的浏览器.

Having followed the TypeScript version of the Angular 2 Quick Start guide, I was wondering if it is possible, and if so how to configure the lite-server to launch a browser other than the default.

似乎lite-server将采用通过yargs.argv提供给它的命令行args.似乎yargs会尝试基于相当通用的标准来解析命令行参数(即,如果令牌以--开头,则表示参数名称,否则表示参数值)以获得argv. lite-server将尝试使用从argv获取的open属性,该属性最终是通过[启动进程的节点程序包之一]启动浏览器的.节点开放? xdg-打开?不确定,只要我的假设(基于对这些流程启动器中的几个进行观察)正确,就对我而言现在并不那么重要,因为他们都可以选择定义启动流程的参数.如果省略,将使用默认浏览器,因为打开的文件类型为html.

It seems lite-server will take command line args, served to it via yargs.argv. And it seems yargs will attempt to parse command line args based on fairly common standards (i.e. If a token begins with a --, it represents an argument name, otherwise an argument value) to obtain argv. lite-server will attempt to use the open property that it gets from argv, which is ultimately what launches the browser via [one of the of the node packages that launches processes]. node-open? xdg -open? Not sure, not really as important to me right now as long as my assumption (based on looking at several of these process launchers) is correct, that they all optionally take an argument defining the process to launch. If omitted, the default browser would be used since the file type to open is html, which is what happens.

如果一切正确,或者至少是要点,那么看来我只需要指定--open chrome,例如(假设chrome在我的PATH中-在win机器上工作).在package.json中定义的lite命令的结尾.

If all that is correct, or at least the gist of it, then it seems I just need to specify --open chrome, for example (assuming chrome is in my PATH - working on a win machine btw), at the end of the lite command defined in package.json.

类似...

"scripts": {
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "lite:c": "lite-server --open chrome",
    "lite:f": "lite-server --open firefox ",
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
},

如果这看起来很愚蠢,我深表歉意,但是我几天后都不会在计算机上可以对此进行测试,因此我需要知道是否有答案,并且可以停止对此进行研究:).谢谢!

I apologize if this seems inane, but I won't be at a computer where I can test this for a few days, and I need to know if I have the answer and can stop researching this :). Thanks!

推荐答案

最近的更改(@ 2.1.0)可让您通过bs-config.json设置配置,包括浏览器:

Recent changes (@2.1.0) let you set your configs, including browser(s), via bs-config.json:

{
  "browser": "chrome"
}

{
  "browser": ["chrome","firefox"]
}

如果要为每个浏览器设置单独的脚本,则可以在package.json中执行以下操作:

If you want to set up separate scripts for each broswer you can do the following in your package.json:

{
  "scripts": {
    "lite": "lite-server",
    "lite:ff": "lite-server --c bs-firefox.json",
    "lite:c": "lite-server --c bs-chrome.json",
    "lite:ie": "lite-server --c bs-ie.json",
    "lite:all": "lite-server --c bs-all.json"
  }
}

虽然这不是最佳解决方案,因为您必须将配置复制并维护为多个文件,但这似乎是lite-server维护人员想要的.这是当前的精简版-server.js 文件以供参考.

While it's not the best solution since you have to copy and maintain your config in multiple files, it seems to be what is intended by the lite-server maintainer. Here's the current lite-server.js file for reference.

这篇关于在angular2快速入门指南中使用lite-server打开非默认浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆