简体   繁体   English

为 web 主机发布 angular 2 应用程序的最佳方式

[英]Best way to publish angular 2 app for web host

Assuming I'm not using the angular-cli, What would be the best way create the dist folder with all the required files for uploading to a web host in order to publish my app?假设我没有使用 angular-cli,创建包含所有必需文件的dist文件夹的最佳方法是什么,以便上传到 web 主机以发布我的应用程序?

My project is based on the angular 2 quickstart, Structed like this on localhost:我的项目基于 angular 2 quickstart,在本地主机上的结构如下:

在此处输入图像描述

TL;DR; TL; DR; Read this article on how to create a consist building process while angular-cli doesn't reach a stable version. 阅读这篇文章 ,了解如何在angular-cli无法达到稳定版本的情况下创建构建构建过程。

It all comes to the module loader used in your project. 所有这些都涉及项目中使用的模块加载器。 From what I've seen in the community the most used are SystemJS(the same as yours) and webpack. 从我在社区中看到的最常用的是SystemJS(与您的相同)和webpack。 In either cases you'll need a build process to create a distribution package of your application. 在这两种情况下,您都需要一个构建过程来创建应用程序的分发包。

Things to know. 事情要知道。

SystemJS : It's simpler to configure but require external tools for building processes. SystemJS :配置更简单,但需要用于构建过程的外部工具。

Webpack : Harder to configure, but It can do almost everything from module loading to app distribution. Webpack :较难配置,但是它几乎可以完成从模块加载到应用分发的所有工作。

For both tools you have the following options 对于这两种工具,您都有以下选择

Use a seed project. 使用种子项目。

Pros : It will have a lot of features ready and easy to use out of the box. 优点 :它具有许多现成的功能,易于使用。 For instance, in a good seed project you'll be able to build your app with a simple npm command. 例如,在一个好的种子项目中,您将可以使用简单的npm命令来构建您的应用程序。

Cons : Sometimes the seed project does much more than what you need; 缺点 :有时种子项目的工作超出了您的需求; Errors might be harder to track. 错误可能更难追踪。

For example, for webpack there's the angular2-webpack-start . 例如,对于webpack,有angular2-webpack-start

Configure everything from scratch 从头开始配置所有内容

Pros : You'll have a full understanding of everything happening in your app; 优点 :您将完全了解应用程序中发生的一切; Errors are easier to track. 错误更容易跟踪。

Cons : Requires additional research on which tools you'll need to use; 缺点 :需要进一步研究您需要使用哪些工具; Setting everything up can be hard. 设置所有内容可能很困难。

Additionally to those options, there's the angular-cli project, which is pretty much a working in progress, but has been highly endorced by angular team. 除了这些选项之外,还有angular-cli项目,该项目正在进行中,但得到了angular团队的高度认可。

Conclusion 结论

I wouldn't use a seed project since I want to know what is happening in my app, however I believe that angular-cli is solid project and once it gets to a stable version I will adopt it. 因为我想知道我的应用程序中发生了什么,所以我不会使用种子项目,但是我相信angular-cli是可靠的项目,一旦它达到稳定的版本,我就会采用它。

In the mean time, I'm configuring everything from scratch and following this amazing article from Mink Gechev on how to optimize building process. 同时,我从头开始配置所有内容,并关注Mink Gechev的这篇精彩文章 ,介绍如何优化构建过程。

There are a few different ways to publish an Angular 2 app to a web host, depending on your specific use case and hosting environment.有几种不同的方法可以将 Angular 2 应用程序发布到 web 主机,具体取决于您的特定用例和托管环境。 Here are a few common methods:下面介绍几种常用的方法:

Using the Angular CLI: The Angular CLI (Command Line Interface) provides a command for building an Angular app for production, which creates a minified version of the app in the "dist" folder.使用 Angular CLI:Angular CLI(命令行界面)提供了一个用于构建 Angular 生产应用程序的命令,该命令会在“dist”文件夹中创建应用程序的缩小版本。 You can then upload the contents of this folder to your web host.然后您可以将此文件夹的内容上传到您的 web 主机。 To build the app, you can run the following command: ng build --prod要构建应用程序,您可以运行以下命令:ng build --prod

Using a build tool: There are a variety of build tools available that can be used to automate the process of building and deploying an Angular app, such as Webpack, which can be configured to build and optimize your app for production.使用构建工具:有多种可用的构建工具可用于自动化构建和部署 Angular 应用程序的过程,例如 Webpack,可以配置它来构建和优化您的应用程序以用于生产。

Using a continuous integration (CI) service: You can set up a CI service like Jenkins, Travis CI, or CircleCI to automatically build and deploy your app whenever changes are pushed to a specific branch of your version control system.使用持续集成 (CI) 服务:您可以设置 CI 服务,如 Jenkins、Travis CI 或 CircleCI,以便在将更改推送到版本控制系统的特定分支时自动构建和部署您的应用程序。

Deploying to Firebase hosting: Firebase is a popular hosting platform from Google that allows you to deploy your Angular 2 app quickly and easily.部署到 Firebase 托管:Firebase 是 Google 的一个流行托管平台,可让您快速轻松地部署您的 Angular 2 应用程序。 Once you have created a Firebase project, you can use the Firebase CLI to deploy your app by running the command firebase deploy创建 Firebase 项目后,您可以使用 Firebase CLI 通过运行命令 firebase deploy 来部署您的应用程序

Deploying to Cloud hosting: You can use any cloud hosting provider such as AWS, Azure, GCP etc to host your application.部署到云托管:您可以使用任何云托管提供商,如 AWS、Azure、GCP 等来托管您的应用程序。 They provide the option to deploy your application.它们提供了部署应用程序的选项。 It needs some initial setup and configuration but it is more powerful and scalable than others.它需要一些初始设置和配置,但它比其他的更强大和可扩展。

Overall, the best method for publishing your Angular 2 app will depend on your specific needs and the hosting environment you are using总体而言,发布 Angular 2 应用程序的最佳方法取决于您的具体需求和您使用的托管环境

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM