【问题标题】:BrowserSync command line Cannot GET /BrowserSync 命令行 无法 GET /
【发布时间】:2018-02-15 10:59:20
【问题描述】:

我正在尝试为 HTML 和 CSS 创建一个简单的浏览器同步服务器。

按照Browser Sync documentation 的示例,我有这个带有启动脚本的 package.json:

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "browser-sync start --server 'src' --files 'src'"
  },
  "author": "",
  "license": "",
  "devDependencies": {
    "browser-sync": "^2.23.6"
  }
}

我的文件夹结构是:

node_modules
src
└───index.html
package.json

但是,当我执行 npm start 时,浏览器会在 http://localhost:3000/ 打开,但它只显示 Cannot GET /

【问题讨论】:

    标签: html npm browser-sync npm-scripts


    【解决方案1】:

    package.json 中的start 脚本更改为以下内容:

    ...
    "scripts": {
      "start": "browser-sync start --server \"src\" --files \"src/**\"",
    },
    ...
    

    备注

    1. --server--files 的路径参数都包含在转义的双引号中。 (即\"...\")因为Windows 无法识别单引号(即'...'
    2. --files 参数已从 'src' 更改为 \"src/**\" - 现在包括 /** 全局模式。

    【讨论】:

    • 这对我有帮助,我遇到了同样的问题。问题在于使用单引号。 /** 全局模式不是必需的。
    猜你喜欢
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-18
    • 2015-05-11
    • 2018-10-08
    • 2013-11-30
    • 2019-08-04
    相关资源
    最近更新 更多