Angular 2 CLI - 部署

dan*_*v91 3 deployment angular-cli angular

我使用Angular 2 CLI构建了一个Angular 2应用程序.我的问题是,现在我想将应用程序部署到本地服务器,作为其他人可以查看的临时环境.

大多数使用Angular 2 CLI的教程都显示了一个dist文件夹,该文件夹似乎是在使用CLI首次创建项目时生成的.我只能dist使用生成文件夹ng build.我假设Angular 2 CLI更改了最初dist文件夹是初始文件夹结构的一部分,但现在它只在使用时生成ng build

作为测试,我将生成的dist文件夹复制到wwwWAMP服务器的文件夹[ http:// localhost:8080/Project/dist /]以尝试运行应用程序...浏览器控制台显示:

Failed to load resource: the server responded with a status of 404 (Not Found)      http://localhost:8080/inline.js
Failed to load resource: the server responded with a status of 404 (Not Found)      http://localhost:8080/bundle.js
Run Code Online (Sandbox Code Playgroud)

它在本地服务器的根目录中查找所有资产,而不是将根目录设置为dist文件夹中index.html的位置.所有的图像和图标都有同样的问题......我想我没有为相对路径配置一些东西......我该怎么办?

Yur*_*uri 6

首先,您可以指定ng build命令的输出路径- 因此不需要手动复制.例如:ng build --output-path /var/www/app_foo/root/.

其次,在- 中实现了基本路径概念作为基本标记.您可以手动或在建筑过程中进行设置.index.html<base href="/path">ng build --base-href /path/

在你的情况下它似乎应该匹配:ng build --base-href /Project/dist/.