npm启动

starts the react server on the default browser, which is Firefox for me. I like Firefox for browsing but prefer Chrome in web development for its developer tools. Is there a way to force "npm启动" to start the server with Chrome, without changing my default browser to chrome? I am using Bash on Windows.

Edit: I used "create-react-app" to create my server and this adds a script to "packages.json" file for "npm启动". The script starts the localhost server with the default browser. How do I modify the script added by "create-react-app" such that it starts with a different browser?

推荐答案

这在使用BROWSER环境变量时是可能的.

您也可以直接在终端中执行:

这一点在Advanced Configuration docs页中有描述:

默认情况下,Create React App将打开默认的系统浏览器,在macOS上使用Chrome浏览器.指定浏览器以覆盖此行为,或将其设置为"无"以完全禁用.如果需要自定义浏览器的启动方式,可以指定 node 脚本.传递给npm start的任何参数也将被传递到此脚本,并且提供应用程序的url将是最后一个参数.脚本的文件名必须具有.js扩展.

还请注意,不同平台上的浏览器名称不同:

应用程序名称取决于平台.不要在可重用模块中硬编码.例如,Chrome是macOS上的google Chrome、Linux上的google Chrome和Windows上的Chrome.

Node.js相关问答推荐

Windows上使用ES6+的OpenAPI规范的Express服务器不接受嵌套路由'

nest js控制器方法调用两次

为什么在导出的函数中调用node-sqlite3中的数据库方法时不起作用?

聚合操作不返回任何具有mongoose模式的内容

如何使用Nextjs路由从下一步/导航在新选项卡中通过";router.ush";打开链接

验证器功能在mongoose 中不起作用

Angular Build 生产返回致命的 javascript 无效大小错误

Mocha调用所有it回调模拟(测试中间件)

node Axios 创建全局令牌变量以在单独的变量头中使用

npm chokidar 触发事件两次

MongoDB 根据使用聚合的条件从嵌套数组中删除对象

Mongoose-更新嵌套数组

响应发送 200 而不是 403

通过 npm 导入 Sass

从 CoffeeScript 中的数组中删除一个值

使用 ES6 语法和动态路径导入模块

webpack css-loader 在外部样式表的 url() 引用中找不到图像

Node.js `--nolazy` 标志是什么意思?

使用 node 的内置调试器判断变量?

使用 node.js 循环 JSON