如何编辑 npm 配置文件?

How do I edit the npm config file?

我遇到了阻止 npm live-server 在启动时打开默认浏览器的问题。我找到的解决方案说我从我的项目中编辑 bs-config.js 以防止这种行为。问题是我没有项目,我只是 运行 我的 vue-js 文件(没有项目,除了 app.js、index.html、styles.css 之外没有文件).

那么如何全局编辑 npm 行为?

我是 运行 来自 git-bash 的实时服务器。

你可以试试这个:

~/.live-server.json

{
  port: 8181, // Set the server port. Defaults to 8080.
  host: "0.0.0.0", // Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP.
  open: false, // When false, it won't load your browser by default.
  logLevel: 2, // 0 = errors only, 1 = some, 2 = lots
}

检查 this 以查看更多配置参数。

在您的项目目录中键入 live-server 时将附加开关 --no-browser 传递给它

例如

live-server --no-browser

有关详细信息,请阅读给定项目的文档 here

如果您是 运行 它来自命令行,只需包含以下标志:

live-server --no-browser 

此外,查看源代码,.live-server.json 应该是 json 文件而不是 javascript 模块:

{

  port: 8181, // Set the server port. Defaults to 8080.
  host: "0.0.0.0", // Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP.
  open: false, // When false, it won't load your browser by default.
  logLevel: 2, // 0 = errors only, 1 = some, 2 = lots
}