如何在共享主机上部署一个简单的 Angular2 应用程序? [英] How to deploy a simple Angular2 app on a shared hosting?

查看:28
本文介绍了如何在共享主机上部署一个简单的 Angular2 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的共享主机上部署我的 Angular2 应用程序.我尝试通过 ssh 传输文件,但该应用程序无法运行.我想有一些事情可以做,比如在本地提供 ng 服务.

I'd like to deploy my Angular2 app on my shared hosting. I tried transferring the files via ssh, but the app doesn't run. I guess there is something to do like the ng serve on local.

要遵循的步骤是什么?我在互联网上找不到它们:/

What do are the steps to follow ? I couldn't find them on the internet :/

谢谢

我有一个非常简单的应用程序,其中包含一些路由和组件.没有服务器端代码,因为我正在根据需要调用 REST api.

I have a very simple app with a few routes and components. No serverside code since I'm calling my REST api for my needs.

推荐答案

在本地开发机器上执行 ng build --prodng build --prod --aot

On your local development machine do an ng build --prod or ng build --prod --aot

这会将您的应用程序构建到 dist 文件夹中.将 dist 文件夹的内容复制到共享主机的公共目录.

This will build your app into the dist folder. Copy the contents of your dist folder to the public directory of your shared hosting.

根据您的主机,您可能需要配置网络服务器(nginx、Apache、IIS 等)来为您的文件提供服务.不要在您的共享主机上运行 ng serve.

Depending on your hosting you may need to configure a web server (nginx, Apache, IIS, etc) to serve your files. Don't run ng serve on your shared hosting.

除非您计划在通用模式下运行您的应用程序,它会在服务器端重新呈现页面,否则不要将您的整个应用程序复制到您的共享主机.不要在您的共享主机上进行 npm 安装.只需将构建的应用程序文件复制到 dist 文件夹中即可.

Unless you plan on running your application in Universal mode, where it rerenders pages server side, do not copy your entire app to your shared host. Do not do an npm install on your shared host. Just copy the built application files in the dist folder.

这篇关于如何在共享主机上部署一个简单的 Angular2 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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