Angular2应用程序构建,但加载css,js文件夹时找不到文件

San*_*N S 2 javascript node.js angular

我有一个angular2应用程序,它使用nodejs服务器api.我使用nd b构建应用程序,它在dist文件夹中创建了文件.我在哪里可以为生产版本指定生产URL,以便正确加载所有css,js文件.在此输入图像描述

而且,我是否需要apache服务器来托管这些构建.或者我可以使用节点服务器本身来托管它吗?

index.html的:

<!doctype html>
<html>
<head>
  <base href="/">
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Demo</title>
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" href="assets/styles/css/custom.css"/>
  <script src="assets/vendor/pace/pace.js"></script>
</head>
<body>
  <app-root>
    <div class="loading"></div>
  </app-root>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

谢谢

Jij*_*tus 7

通过分析您的html文件,我发现<base>标签存在问题.

你需要提供./而不是/错误.更正的html文档如下.

<!doctype html>
<html>
<head>
  <base href="./"> <!-- use ./ instead of / -->
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>SHEPHERD SHIELD</title>
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" href="assets/styles/css/custom.css"/>
  <script src="assets/vendor/pace/pace.js"></script>
</head>
<body>
  <app-root>
    <div class="loading"></div>
  </app-root>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)