且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在共享主机上部署一个简单的 Angular2 应用程序?

更新时间:2022-06-10 05:52:53

在本地开发机器上执行 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.