在没有服务器的浏览器中将Angular2作为静态应用程序运行 [英] Run Angular2 as static app in browser without a server

查看:88
本文介绍了在没有服务器的浏览器中将Angular2作为静态应用程序运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,Angular2概念是将TypeScript文件转换为.js文件.原则上,应该可以从AWS S3存储桶,GitHub或任何静态源中编译,打包然后将Angular2应用程序作为静态应用程序运行.

As I understand the Angular2 concept - it is transpiling TypeScript files to .js files. In principle, it should be possible to compile, package, and then run that Angular2 application as a static application from AWS S3 bucket, GitHub or whatever static source.

如果我在节点服务器上运行Angular2应用程序(使用angular-cli"ng serve"命令),则它将在服务器上占用500 MB的RAM-这是嘿,很普通!" -真的应该那样吗!那么,例如,该框架相对于仅需一个浏览器的React的好处是什么.

If I run Angular2 application on node server (with angular-cli "ng serve" command), it takes 500 MB of RAM on server - it's "Heey, common!" - is it really supposed to be that way! What's the benefit of this framework then against React, for example, which needs only a browser.

对于将Angular2应用程序作为静态编译的HTML + JS服务,我似乎找不到任何有用的东西.

I can't seem to find anything useful on serving Angular2 application as a static compiled HTML+JS.

也许您可以帮助我理解并解决?

Maybe you can help me understand this, and solve?

非常感谢!

马里斯

推荐答案

运行 已构建 命令以 BUNDLE /build

ng构建

ng build

或用于生产版本/捆绑包

or for a production build/bundle

ng build --prod

ng build --prod

它将把您的应用程序构建/捆绑到可分发的应用程序中.

It will build/bundle your app into a distributable app.

完成后,在您的应用程序根目录中查找dist文件夹,该文件夹将包含您的应用程序需要在节点服务器外部运行的所有内容,例如tomcat实例.

When it is finished look in your apps root directory for a dist folder and that will contain everything your app needs to run in outside of the node server, say like a tomcat instance.

更新

感谢@Maris的评论,请确保您的文件路径是相对于当前目录而不是相对于根目录的.

Thanks to the comment from @Maris, make sure your file paths are relative to the current directory rather than relative to the root directory.

只需运行此命令即可更改index.html中的基本href元素.

Simply run this command to change the base href element in your index.html.

ng build --prod --base-href ./

ng build --prod --base-href ./

这篇关于在没有服务器的浏览器中将Angular2作为静态应用程序运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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