如何将 Angular Universal 项目部署到标准托管? [英] How to deploy Angular Universal project to standard hosting?

查看:20
本文介绍了如何将 Angular Universal 项目部署到标准托管?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Angular Universal 项目在我的本地主机上运行.所以现在我想在安装了 Node.js 的标准虚拟主机上测试它.

我已经跑了:

npm 运行构建

并收到 dist 文件夹,其中包含 clientserver 子文件夹.

我应该如何使用这些文件夹和文件来在主机上运行项目?

谢谢.

解决方案

所以我已经将我的 Angular Universal 项目部署到我的主机上.

我可以说我托管的支持团队给了我很多帮助.不知道能不能自己部署这样的项目.

我的主机支持 Node.js.主机的支持团队给了我一个说明如何使用 终端 在主机上安装 Node.jsMac 或适用于 Windows 的程序,例如 PuTTY.

然后我完成了以下步骤:

  1. 在主机上为项目创建文件夹.
  2. dist 文件夹复制到创建的文件夹中.
  3. 在项目文件夹中安装 NPM.在这一步,支持团队给了我一些帮助.因为你应该用 PATH 做一些事情正确安装和运行 NPM.
  4. 标准托管将 public_html 文件夹链接到您的域名.但是 Angular Universal 项目应该在一个单独的文件夹中.所以我要求支持将我的域重定向到 Angular项目文件夹和正确的端口.
  5. 使用终端运行服务器:

<块引用>

节点 dist/server/server.js

毕竟我可以看到我的项目在我的域名上运行良好.

添加.我也尝试了以下方法:将我的项目文件夹(没有 node_modules 文件夹)复制到托管,然后运行 ​​

<块引用>

npm 安装

npm 运行构建

您也可以通过这些命令在主机上创建 dist 文件夹.

添加.假设您在主机上配置了 Node.js 服务器.此外,您应该确保您的项目已准备好部署.这是一个链接,代码需要准备这个:https://github.com/angular/angular-cli/wiki/stories-universal-rendering

您还需要在您的主机上复制您的 client/server/ 文件夹以及 server.js 包.json 文件.然后你可以运行你的应用程序

<块引用>

节点 server.js

I have my Angular Universal project working on my localhost. So now I would like to test it on my standard web hosting with Node.js installed.

I have run:

npm run build 

and received dist folder with client and server subfolders.

How should I use these folders and files into them to run the project on the hosting?

Thanks.

解决方案

So I have deployed my Angular Universal project to my hosting.

I can say that the support team of my hosting gave me a lot of help. I don't know if is it possible to deploy such project on the own.

My hosting has a Node.js support. Support team of the hosting gave me an instruction how to install Node.js on the hosting using terminal on Mac or programs for Windows like PuTTY.

Then I walked through the following steps:

  1. Create the folder for the project on the hosting.
  2. Copy the dist folder to created folder.
  3. Install NPM in the project folder. At this step support team gave me some help. Because you should do something with PATH to proper install and work of NPM.
  4. Standard hosting links the public_html folder to your domain name. But Angular Universal project should be in a separate folder. So I have asked the support to redirect my domain to the Angular project folder and proper port.
  5. Run server using terminal:

node dist/server/server.js

After all I can see my project working good on my domain name.

Addition. Also I tried the following way: copied my project folder (without node_modules folder) to the hosting and then run

npm install

npm run build

You can create the dist folder on the hosting also by these commands.

Addition. Assume that you config your Node.js server on your hosting. Also you should make shure that your project ready to be deployed. Here is a link what code needs to prepair this: https://github.com/angular/angular-cli/wiki/stories-universal-rendering

You also need to copy on your hosting your client/ and server/ folders and also server.js and package.json files. Then you can run your application by

node server.js

这篇关于如何将 Angular Universal 项目部署到标准托管?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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