【问题标题】:ng build - getting 404 for all static assetsng build - 为所有静态资产获取 404
【发布时间】:2018-12-08 04:10:14
【问题描述】:

我使用 @angular/cli 生成了一个 Angular 7 应用程序,我没有更改任何内容,所有默认设置 - 我刚刚在 20 分钟前创建它。

当我运行 ng buildng build --prod 时,它会将构建放入:

dist/
  appname/

在我的情况下是

dist/
  api-app/

看起来像这样:

奇怪的是,当我加载 index.html 时,我得到所有静态资源的 404:

<-- [GET] /
--> 200 OK / (dist/api-app/index.html) 592 Byte (19.188ms)
<-- [GET] /styles.3ff695c00d717f2d2a11.css
<-- [GET] /runtime.ec2944dd8b20ec099bf3.js
--> 404 /styles.3ff695c00d717f2d2a11.css (2.416ms)
--> 404 /runtime.ec2944dd8b20ec099bf3.js (2.236ms)
<-- [GET] /polyfills.20ab2d163684112c2aba.js
<-- [GET] /main.9113cc683ed9b1c834cf.js
--> 404 /polyfills.20ab2d163684112c2aba.js (0.471ms)
--> 404 /main.9113cc683ed9b1c834cf.js (0.550ms)
<-- [GET] /styles.3ff695c00d717f2d2a11.css
--> 404 /styles.3ff695c00d717f2d2a11.css (0.732ms)

我尝试使用多个不同的服务器加载 index.html 页面,但静态资源总是得到 404。有谁知道为什么?这是 index.html 文件:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>ApiApp</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" href="styles.3ff695c00d717f2d2a11.css">
</head>
<body>
<app-root></app-root>
<script type="text/javascript" src="runtime.ec2944dd8b20ec099bf3.js"></script>
<script type="text/javascript" src="polyfills.20ab2d163684112c2aba.js"></script>
<script type="text/javascript" src="main.9113cc683ed9b1c834cf.js"></script>
</body>
</html>

【问题讨论】:

    标签: angular angular-cli angular-cli-v7


    【解决方案1】:

    原因是我运行的 Web 服务器的根目录错误。我这样做了:

    $ npm i -g static-server
    $ cd dist/api-app
    $ static-server
    

    现在可以了

    【讨论】:

      猜你喜欢
      • 2018-05-24
      • 1970-01-01
      • 1970-01-01
      • 2017-01-04
      • 2016-01-24
      • 2015-02-09
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      相关资源
      最近更新 更多