typescript 将 Angular 2 应用程序部署到 Azure

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35194743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:15:10  来源:igfitidea点击:

Deploy Angular 2 App to Azure

azuretypescriptangular

提问by Frank Liu

I am learning Angular 2 and Azure. I followed along the Angular 2 Tutorialand everything worked fine locally.

我正在学习 Angular 2 和 Azure。我遵循了Angular 2 教程,一切都在本地运行良好。

I published the app to Azure. The publication was successfully. But when I visit the site it stuck at the loading stage. Looking at logs in the Chrome console I see the following error. The /app/main.tsfile is not found.

我将该应用程序发布到 Azure。发布成功。但是当我访问该网站时,它停留在加载阶段。查看 Chrome 控制台中的日志,我看到以下错误。/app/main.ts未找到该文件。

enter image description here

在此处输入图片说明

I checked my deployed files via the "Kudu" dashboard as suggested by this question. I dont see any *.tsare deployed only the *.jsand *.map.

我按照这个问题的建议通过“Kudu”仪表板检查了我部署的文件。我没有看到任何*.ts部署只有*.js*.map

enter image description here

在此处输入图片说明

Then I went back to Visual Studio changed the property of all *.tsfile to Copy Always. After the change, I can see that the *.tsfiles are copied to the .\bin\appdirectory. However, after I republished the project to Azure (successfully again), I still ended up with the 404 error when requesting the main.tsfile.

然后我回到 Visual Studio 将所有*.ts文件的属性更改为Copy Always. 更改后,我可以看到*.ts文件被复制到.\bin\app目录中。但是,在我将项目重新发布到 Azure(再次成功)后,我在请求main.ts文件时仍然以 404 错误告终。

According to the this questionIIS does not serve Typescript file correctly.

根据这个问题IIS 没有正确提供 Typescript 文件。

Firstly: How to apply suggested change on Azure to fix it?

首先:如何在 Azure 上应用建议的更改来修复它?

Secondly: why do we need to use the *.tsfiles? Based on my understanding, the *.tsis complied into *.js. Why can't we just request the *.jsfiles which are correctly deployed to Azure ?

其次:为什么我们需要使用这些*.ts文件?根据我的理解,*.ts符合*.js. 为什么我们不能只请求*.js正确部署到 Azure的文件?

采纳答案by Xiaomin Wu

@Frank,

@坦率,

use .ts file is just for demo and tutorial, it is actually suggested to run your site with .js file.

使用 .ts 文件仅用于演示和教程,实际上建议使用 .js 文件运行您的站点。

i have a sample app running which you might be able to reference a bit to see how it work.

我有一个正在运行的示例应用程序,您可以参考一下它以了解它是如何工作的。

https://github.com/shrimpy/AspMVCFileUploadSample

https://github.com/shrimpy/AspMVCFileUploadSample

  • Asp.net Core 1.0.0-rc1
  • Angularjs 2
  • Asp.net 核心 1.0.0-rc1
  • Angularjs 2

hope this will help.

希望这会有所帮助。

回答by user1912383

Here are the steps i followed:

以下是我遵循的步骤:

  1. make sure angular 2 app builds and runs locally
  2. Create azure web app and get the publish profile
  3. from VS publish the app by importing the downloaded publish profile
  4. Open command line from Azure --> Tools --> Kudu (or Console)
  5. cd to home\site\wwwroot
  6. execute: npm install
  1. 确保 angular 2 应用程序在本地构建和运行
  2. 创建 azure Web 应用程序并获取发布配置文件
  3. 通过导入下载的发布配置文件从 VS 发布应用程序
  4. 从 Azure --> 工具 --> Kudu(或控制台)打开命令行
  5. cd 到 home\site\wwwroot
  6. 执行: npm install