【问题标题】:Page working with `grunt serve` but not when I load index.html页面使用“grunt serve”,但在我加载 index.html 时没有
【发布时间】:2015-09-23 15:22:07
【问题描述】:

GitHub 仓库:https://github.com/grahamlutz/MyVirtualPack

当我使用 grunt serve 启动一个监听 localhost:9000 的服务器时,页面看起来和工作正常。当我尝试在浏览器中加载 index.html 时,我无法访问 bower_components 文件夹,该文件夹是目录中 index.html 上方的文件夹。

GET file:///bower_components/modernizr/modernizr.js net::ERR_FILE_NOT_FOUND
index.html:190 GET file:///bower_components/jquery/dist/jquery.js net::ERR_FILE_NOT_FOUND               -      index.html:195 

GET file:///bower_components/bootstrap-sass/assets/javascripts/bootstrap/affix.js net::ERR_FILE_NOT_FOUND                  - index.html:196

GET file:///bower_components/bootstrap-sass/assets/javascripts/bootstrap/alert.js net::ERR_FILE_NOT_FOUND                   -    index.html:196

...等等。

我不知道具体要问什么,希望我不知道在使用 grunt serve 时会发生什么不同?

【问题讨论】:

  • 当您使用grunt serve 或任何其他服务器时,它将使用服务器的相对路径并且可以正常工作。当你在没有服务器的情况下运行 index.html 时,文件路径不正确,所以它不起作用。
  • 谢谢@Tushar。那么有没有办法在运行 index.html 时使用相对路径?另外,如果/当我用 goDaddy 之类的东西托管它时,它会使用相对路径吗?

标签: javascript jquery angularjs twitter-bootstrap gruntjs


【解决方案1】:

实际上,您的问题是由 absolute 路径引起的:这些路径以第 191 行及更多的“/”开头。 它们在 http: 请求(grunt serve 或您的 GoDaddy)的上下文中工作正常,但在简单的 file: 请求(这是您在浏览器中加载本地文件时得到的)时无法正常工作。

将它们替换为相对路径 (../bower_components/[...]),您应该会很好 - 这可能需要对您的有线配置进行一些工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 2015-09-13
    • 1970-01-01
    • 2017-01-04
    • 2015-01-13
    • 1970-01-01
    相关资源
    最近更新 更多