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
Deploy Angular 2 App to Azure
提问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.ts
file is not found.
我将该应用程序发布到 Azure。发布成功。但是当我访问该网站时,它停留在加载阶段。查看 Chrome 控制台中的日志,我看到以下错误。/app/main.ts
未找到该文件。
I checked my deployed files via the "Kudu" dashboard as suggested by this question. I dont see any *.ts
are deployed only the *.js
and *.map
.
我按照这个问题的建议通过“Kudu”仪表板检查了我部署的文件。我没有看到任何*.ts
部署只有*.js
和*.map
。
Then I went back to Visual Studio changed the property of all *.ts
file to Copy Always
. After the change, I can see that the *.ts
files are copied to the .\bin\app
directory. However, after I republished the project to Azure (successfully again), I still ended up with the 404 error when requesting the main.ts
file.
然后我回到 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 *.ts
files? Based on my understanding, the *.ts
is complied into *.js
. Why can't we just request the *.js
files 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:
以下是我遵循的步骤:
- make sure angular 2 app builds and runs locally
- Create azure web app and get the publish profile
- from VS publish the app by importing the downloaded publish profile
- Open command line from Azure --> Tools --> Kudu (or Console)
- cd to home\site\wwwroot
- execute: npm install
- 确保 angular 2 应用程序在本地构建和运行
- 创建 azure Web 应用程序并获取发布配置文件
- 通过导入下载的发布配置文件从 VS 发布应用程序
- 从 Azure --> 工具 --> Kudu(或控制台)打开命令行
- cd 到 home\site\wwwroot
- 执行: npm install