且构网

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

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

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

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

根据您的托管情况,您可能需要配置Web服务器(nginx,Apache,IIS,等)来提供你的文件。不要在共享主机上运行服务。

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.