您如何部署Angular应用程序? [英] How do you deploy Angular apps?

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

问题描述

一旦Angular应用进入生产阶段,您将如何部署它们?

How do you deploy Angular apps once they reach the production phase?

到目前为止,我看过的所有指南(甚至在 angular.io 上)都依赖于lite服务器用于服务和browserSync以反映更改-但是在完成开发后,如何发布该应用程序?

All the guides I've seen so far (even on angular.io) are counting on a lite-server for serving and browserSync to reflect changes - but when you finish with development, how can you publish the app?

我是否要在index.html页面上导入所有已编译的.js文件,还是使用gulp来缩小它们?他们会工作吗?生产版本中是否完全需要SystemJS?

Do I import all the compiled .js files on the index.html page or do I minify them using gulp? Will they work? Do I need SystemJS at all in the production version?

推荐答案

您实际上是在碰触两个问题.

You are actually here touching two questions in one.

第一个如何托管您的应用程序?.
正如@toskv所提到的那样,它的问题实在太广泛了,无法回答,取决于许多不同的事物.

The first one is How to host your application?.
And as @toskv mentioned its really too broad question to be answered and depends on numerous different things.

第二个如何准备应用程序的部署版本?.
您在这里有几种选择:

The second one is How do you prepare the deployment version of the application?.
You have several options here:

  1. 按原样部署.就是这样-无需进行任何缩小,串联,名称修饰等操作.转换所有ts项目,然后将所有生成的js/css/...源+依赖项复制到托管服务器,您就可以开始了.
  2. 使用特殊的捆绑工具(例如webpacksystemjs构建器)进行部署.
    它们具有#1中缺少的所有可能性.
    您可以将所有应用程序代码打包到您在HTML中引用的js/css/...文件中. systemjs构建器甚至允许您摆脱将systemjs作为部署软件包的一部分的需要.

  1. Deploy as it is. Just that - no minification, concatenation, name mangling, etc. Transpile all your ts project copy all your resulting js/css/... sources + dependencies to the hosting server and you are good to go.
  2. Deploy using special bundling tools, like webpack or systemjs builder.
    They come with all the possibilities that are lacking in #1.
    You can pack all your app code into just a couple of js/css/... files that you reference in your HTML. systemjs builder even allows you to get rid of the need to include systemjs as part of your deployment package.

从Angular 8开始,您可以使用ng deploy从CLI部署您的应用程序. ng deploy将需要与您选择的平台结合使用(例如@angular/fire).您可以在这里

You can use ng deploy as of Angular 8 to deploy your app from your CLI. ng deploy will need to be used in conjunction with your platform of choice (such as @angular/fire). You can check the official docs to see what works best for you here

是的,您很可能需要将systemjs和其他一系列外部库作为软件包的一部分进行部署.是的,您将能够将它们捆绑到您从HTML页面引用的几个js文件中.

Yes you will most likely need to deploy systemjs and bunch of other external libraries as part of your package. And yes you will be able to bundle them into just couple of js files you reference from your HTML page.

尽管您不必引用页面中所有已编译的js文件-systemjs,因为模块加载程序会解决这一问题.

You do not have to reference all your compiled js files from the page though - systemjs as a module loader will take care of that.

我知道这听起来很泥泞-为了帮助您开始使用#2,这里有两个非常好的示例应用程序:

I know it sounds muddy - to help get you started with the #2 here are two really good sample applications:

SystemJS构建器: angular2种子

SystemJS builder: angular2 seed

WebPack: angular2 webpack入门

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

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