Angular 2 CLI - 部署
Angular 2 CLI - Deployment
我已经使用 Angular 2 CLI 构建了一个 Angular 2 应用程序。我现在的问题是我想将应用程序部署到本地服务器作为其他人查看的暂存环境。
大多数使用 Angular 2 CLI 的教程显示了一个 dist
文件夹,该文件夹似乎是在首次使用 CLI 创建项目时生成的。我只能使用 ng build
生成 dist
文件夹。我假设 Angular 2 CLI 发生了变化,最初 dist
文件夹是初始文件夹结构的一部分,但现在它仅在使用 ng build
时生成?
作为测试,我将生成的 dist
文件夹复制到 WAMP 服务器 [http://localhost:8080/Project/dist/] 的 www
文件夹中以尝试 运行 应用程序...浏览器控制台显示:
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 的位置。所有图像和图标都有同样的问题...我想我没有为相对路径配置一些东西...我该怎么办?
首先,您可以指定ng build
命令的输出路径——因此无需手动复制。例如:ng build --output-path /var/www/app_foo/root/
.
其次,在 index.html
- <base href="/path">
中有一个 base path 概念作为 base tag 实现。您可以手动设置或在构建过程中通过 ng build --base-href /path/
.
在你的情况下它似乎应该匹配:ng build --base-href /Project/dist/
.
我已经使用 Angular 2 CLI 构建了一个 Angular 2 应用程序。我现在的问题是我想将应用程序部署到本地服务器作为其他人查看的暂存环境。
大多数使用 Angular 2 CLI 的教程显示了一个 dist
文件夹,该文件夹似乎是在首次使用 CLI 创建项目时生成的。我只能使用 ng build
生成 dist
文件夹。我假设 Angular 2 CLI 发生了变化,最初 dist
文件夹是初始文件夹结构的一部分,但现在它仅在使用 ng build
时生成?
作为测试,我将生成的 dist
文件夹复制到 WAMP 服务器 [http://localhost:8080/Project/dist/] 的 www
文件夹中以尝试 运行 应用程序...浏览器控制台显示:
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 的位置。所有图像和图标都有同样的问题...我想我没有为相对路径配置一些东西...我该怎么办?
首先,您可以指定ng build
命令的输出路径——因此无需手动复制。例如:ng build --output-path /var/www/app_foo/root/
.
其次,在 index.html
- <base href="/path">
中有一个 base path 概念作为 base tag 实现。您可以手动设置或在构建过程中通过 ng build --base-href /path/
.
在你的情况下它似乎应该匹配:ng build --base-href /Project/dist/
.