Angular 2 CLI - 部署

时间:2016-10-21 02:41:24

标签: angular deployment angular-cli

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

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

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

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

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

1 个答案:

答案 0 :(得分: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/

相关问题