【发布时间】:2019-11-17 21:49:47
【问题描述】:
我正在使用标准 localhost:4200 进行开发。但我也想看看构建是如何工作的。为此,我修改了 angular.json 文件。更改如下所示:
"outputPath": "D:/a_root/dist",
其中 a_root 是所有后端文件和 web.config 所在的应用程序根文件夹。因此,为了不弄乱后端和前端文件,我想将所有前端文件放入子文件夹 /dist。 我想做的是这个。我的项目中有一个文件 index.html。我正在将基本标签更改为:
<base href="/dist">
然后我构建应用程序:
ng build --watch=true
并在正确的位置获取 dist 文件夹。 然后我将 index.file 从 dist 文件夹复制到 a_root 以运行应用程序。
Index.file 看起来像这样:
<head>
<base href="/dist/">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="shortcut icon" href="assets/favicon.ico">
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.min.css"
rel="stylesheet"/>
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
</head>
<body class="app" style="overflow-y: hidden;">
<script src="runtime.js"></script><script src="polyfills-es5.js" nomodule></script><script
src="polyfills.js"></script><script src="styles.js"></script>
<script src="scripts.js"></script><script src="vendor.js"></script>
<script src="main.js"></script>
</body>
</html>
当它作为 localhost/a_root/index.html 运行时,我会立即收到脚本错误,因为它们没有被正确引用。但即使在它们前面加上 dist/ 也有助于加载脚本但无助于运行应用程序。它无法加载第一个 ts 组件。
我在这里做错了什么?
谢谢
【问题讨论】:
-
您是否尝试使用 CLI 命令更改这些设置,例如更改文件夹、基础等
-
我正在显示我正在使用的所有命令。你到底有什么想法?
-
这里有错误:GET localhost:8011/polyfills.jsnet::ERR_ABORTED 404(未找到)16:38:25.620 index.html:37 GET localhost:8011/styles.jsnet::ERR_ABORTED 404(未找到)16: 38:25.621 index.html:37 GET localhost:8011/vendor.js net::ERR_ABORTED 404(未找到) 16:38:25.621 index.html:37 GET localhost:8011/scripts.js net::ERR_ABORTED 404(未找到)16:38:25.622 索引.html:37 GET localhost:8011/main.js net::ERR_ABORTED 404(未找到) 16:38:25.637 index.html:37 GET localhost:8011/vendor.js net::ERR_ABORTED 404(未找到)
-
还有命令:ng build --watch=true --baseHref=dist --outputPath=D:\a_root\dist。构建完成后,我将 dist/index.html 复制到 a_root 并从那里运行它。和我之前的基本一样。
标签: angular angular-cli