angular-cli工具的–base-href和–deploy-url参数之间有什么区别

What's the difference between --base-href and --deploy-url parameters of angular-cli tool

Angular的文档通知我,当将其部署在服务器的子文件夹中时,应在Angular应用程序构建中使用--base-href参数进行生产:

If you copy the files into a server sub-folder, append the build flag,
--base-href and set the appropriately.

For example, if the index.html is on the server at /my/app/index.html,
set the base href to like this.

https://angular.io/guide/deployment

但是,angular-cli具有--deploy-url参数。 该工具的文档将其描述为:

URL where files will be deployed.

https://github.com/angular/angular-cli/wiki/build

我已经看到了将应用程序部署在服务器的子文件夹中时使用--base-href--deploy-url插入的解决方案。

问题

angular-cli工具的--base-href--deploy-url参数之间有什么区别? 我什么时候应该使用每个?


  • 路由正在使用base-href
  • deploy-url用于资产。

在大多数情况下,base-href就足够了。

请查看以下帖子:

  • https://github.com/angular/angular-cli/issues/9835

  • https://shekhargulati.com/2017/07/06/angular-4-use-of-base-href-and-deploy-url-build-options/


要将脚本放入" / test / app1 / script /"文件夹中,请使用以下命令:

1
ng build --prod --base-href /test/app1/ --deploy-url /test/app1/script/

因此,可以在https://example.com/test/app1/上访问我的应用程序,但是我的JS脚本和CSS在https://example.com/test/app1/script/目录中。


如果我想将/ users用作路由器的应用程序基础,并将/ public用作我的资产的基础。

1
ng build --prod --base-href /users --deploy-url /public

有关详细示例,请参见Shekhar Gulati的博客。