如何将用Typescript开发的Angular 2应用程序部署到生产中? [英] How to deploy Angular 2 application developed in Typescript to production?

查看:53
本文介绍了如何将用Typescript开发的Angular 2应用程序部署到生产中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Angular 2的新手.我对Angular 2在生产环境中的工作方式感到困惑.

I am new to Angular 2. I am confused with how Angular 2 works in production environment.

  1. 在生产服务器中运行Angular 2应用程序的先决条件是什么?

  1. What are the prerequisites for running Angular 2 application in production server?

是否可以在IIS服务器中部署应用程序,还是需要节点服务器?

Is it possible to deploy the application in IIS server or is node server required?

在使用node在开发机中编译文件之后,我们是否需要将.js和.ts都部署到生产环境中?

After compiling the file in development machine using node, do we need to deploy both .js and .ts to production?

推荐答案

我使用JSPM来准备我的angular2项目. JSPM等其他流行工具包括webpack和browserfy. JSPM将要完成的重要任务之一是将构成angular2项目的各个模块捆绑在一起.我还将"selfExecutingBundle"标志设置为true,并让JSPM制作了一个捆绑的js文件(例如myApp.bundled.js),然后从中缩小了文件(myApp.bundled.min.js),并且在index.html文件.

I use JSPM to make my angular2 projects production ready. Other popular tools like JSPM include webpack, and browserfy. One of the important tasks that JSPM will accomplish is to bundle the various modules that make up your angular2 project. I also set the "selfExecutingBundle" flag to true and have JSPM make one bundled js file (e.g. myApp.bundled.js) and from there I minify it (myApp.bundled.min.js) and this one script reference is used in the index.html file.

<html>

<head>
    <title>Hello Angular World</title>
</head>
<body>
<div>
    <my-app>Loading...</my-app>
</div>
    <script src="/js/myApp.bundle.min.js"></script>
</body>

</html>

这就是您所需要的!

将来,当HTTP/2规范变得更加普遍时,可能不需要捆绑您的基于模块的项目,但是现在我认为需要捆绑.

In the future when the HTTP/2 spec is more common, there may be less of a need to bundle your module-based projects, but for now I think bundling is needed.

没有引用您的打字稿文件(因为在制作myApp.bundled.js的过程中已经对它们进行了转译).正如Zama所说,您可以在任何服务器上运行angular2(我使用IIS且运行良好).

There is no reference to your typescript files (as they were already transpiled in the process of making the myApp.bundled.js). As Zama said, you can run angular2 on any server (I use IIS and works fine).

更新:自Angular 2的最终版本发布以来,我已切换到使用angular-cli进行生产构建.设置很容易(没有吞咽任务的意大利面),并且最终捆绑包是超级优化的(特别是由于摇晃的树).我建议检查一下angular-cli来进行设置,开发和构建ng2项目.

UPDATE: Since the final release of Angular 2, I have switched to using the angular-cli for building for production. Setup is easy (no spaghetti of gulp tasks) and the final bundle is super-optimized (esp due to tree-shaking). I recommend checking out the angular-cli for setting up, developing with, and building your ng2 projects.

这篇关于如何将用Typescript开发的Angular 2应用程序部署到生产中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆