由于各种原因,我需要将 Angular2 应用程序的 index.html 文件与该应用程序的所有其他文件(javascript、供应商文件、资产等)分开。所有其他文件也必须位于我的域的子目录中。这是一个例子:
assets/
my_app_assets/
main.js
app/
vendor/
html/
index.html
我知道如何告诉 angular-cli 构建过程输出这样的文件,但我一生都无法弄清楚如何告诉
index.html
中的相对路径指向 domain.com/assets/my_app_assets/main.js
而不是 domain.com/main.js
.
您可以使用
baseHref
(https://github.com/angular/angular-cli/blob/b09ce572ed72f19c353e71b7d9d751484c5db63a/packages/angular_devkit/build_angular/src/builders/browser/schema.json#L267)来完成此操作
deployUrl
已被 baseHref
弃用。
信用:
https://github.com/angular/angular-cli/issues/3557#issuecomment-433868214
我使用的是 Angular 6,设置
不足以解决这个问题,但在--base-href
中设置deployUrl
可以解决这个问题。angular.json
您可以在
中设置。projects -> $projectName -> architect -> build -> options
例如
"deployUrl": "/app/"