如何托管angular 2网站? [英] how to host angular 2 website?

查看:102
本文介绍了如何托管angular 2网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何托管Angle 2网站?

How to host angular 2 website?

我是Angle 2的新手,我做了一个没有后端的简单网站.

I am new to angular 2 and I made a simple website with no back-end.

我想知道当我尝试直接打开index.html文件时,它会错误打开.

I wondered that when I tried to open directly index.html file, it opens with error.

但是在命令"npm start"之后,它运行良好,可以在计算机上运行本地服务器.

But after command "npm start" it works fine, which runs a local server on computer.

那么,如何在简单的托管站点(不是专用服务器..!)上托管此网站?

So, how to host this website on simple hosting sites (Not a Dedicated Server..!)?

我认为托管站点会自动找到index.html文件,但这是问题所在,没有"npm start"命令就无法启动index.html.

I think hosting sites automatically find index.html file, but here is the problem, index.html is don't start without "npm start" command.

我必须在服务器上为此启动一个进程吗?

can I have to start an process for that on server?

请引导我.

推荐答案

使用以下简单步骤将您的Angular 2应用托管在 Firebase 上: 首先使用Angular CLI创建一个项目.在此处获取更多信息 https://cli.angular.io/

Host your Angular 2 App on Firebase using these simple steps: Do Create a project with Angular CLI first. Get More info here https://cli.angular.io/

第1步:构建您的应用

运行以下cmd进行构建

Run the below cmd to build

ng build --prod

第2步:创建FireBase项目并安装Firebase CLI

通过 https://console.firebase.google.com/打开Firebase控制台并创建一个新的Firebase项目.

Open the Firebase console at https://console.firebase.google.com/ and create a new Firebase project.

要安装Firebase命令行工具,请运行:

To install the Firebase command line tools run:

npm install -g firebase-tools

第3步:部署到FireBase

运行以下firebase cmd进行登录:

Run the below firebase cmd to login:

firebase login

它将打开浏览器,并要求您进行身份验证.使用您的Firebase帐户登录.之后,您可以关闭浏览器窗口.在命令行上,您将收到一条消息,说明登录已成功完成.

It will open the browser and ask you for authentication. Login with your Firebase account. There after you can close the browser window. On the command line you'll receive the message that the login has been performed successfully.

现在运行以下cmd:

firebase init

首先,系统会询问您要使用哪些Firebase客户端功能.您应该选择托管:配置和部署Firebase托管站点"选项.接下来,Firebase客户端将询问要使用哪个文件夹进行部署.输入 dist .这很重要,因为这是我们的生产版本存储的位置.

First of all you're being asked which of the Firebase client features you want to use. You should select the option Hosting: Configure and deploy Firebase Hosting site. Next the Firebase client will ask which folder to use for deployment. Type in dist. That is important because that is the location where our production build is stored.

接下来的问题是询问此应用程序是否为单页应用程序,以及是否应将所有URL重写为index.html.在我们的情况下,我们需要回答是.

Next the question is ask if this app is a single page app and if it should rewrite all URLs to index.html. In our case we need to answer yes.

最后一个问题是Firebase是否应该重写文件index.html.这个问题的答案是否定的.

Last question is if Firebase should over write file index.html. The answer to that question is no.

现在,运行以下cmd进行部署:

Now, Run the below cmd to deploy:

firebase deploy

Firebase将提供一个 URL ,您可以使用该URL来在线访问您的应用程序.

Firebase will provide a URL which you can use to access your application online.

[更新]

[Update]

现在,如果您要进行一些更改并将代码部署在相同的URL上,则在成功部署应用程序之后.请遵循相同的步骤.但是请确保您指向的是项目.

Now after you have successfully deployed your app if you want to make some changes and deploy the code on same URL. Follow the same procedure. But make sure You are pointing to your project.

要列出所有项目,请使用以下命令:

firebase list

要将一个项目用作当前项目,请执行以下操作:

firebase use <project_id>

这篇关于如何托管angular 2网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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