简体   繁体   English

AngularJS应用程序部署最佳实践? 使用CDN?

[英]AngularJS app deployment best practices? Use a CDN?

What are the best practices to deploy in production an AngularJS App? 在AngularJS App的生产中部署哪些最佳实践? Is using a CDN the way to go? 使用CDN的方式去哪儿了?

An AngularJS app is afterall only static files so instead of having NodeJS or even Nginx serve the files, it looks like it'd be better to just use a CDN to not worry about all these static files and focus on running the API backend that the AngularJS app would use. 一个AngularJS应用程序只是静态文件,所以没有NodeJS甚至Nginx提供文件,看起来最好只使用CDN不要担心所有这些静态文件,并专注于运行API后端,即AngularJS应用程序将使用。

I would like to get to the point where I can have 2 distinct projects: - one being only the AngularJS app - one being only the API backend served by NodeJS 我想谈谈我可以有两个不同的项目: - 一个只是AngularJS应用程序 - 一个只是NodeJS提供的API后端

I am having a hard time to see how to setup such a development environment that would be easy to deploy in production as well. 我很难看到如何设置这样一个易于在生产中部署的开发环境。 I am new to AngularJS/NodeJS and all the tutorials I have found put everything together. 我是AngularJS / NodeJS的新手,我找到的所有教程都将所有内容放在一起。

Any advice? 有什么建议? Examples? 例子?

Thanks 谢谢

You can definitely use a CDN, or anything that acts the same way – Amazon S3 is a common solution, but the simplest is probably GitHub Pages : Just make sure your files are organized the way they want them (in a branch called "gh-pages" and it should work fine. 您绝对可以使用CDN或任何行为相同的方式 - Amazon S3是一种常见的解决方案,但最简单的可能是GitHub页面 :只需确保您的文件按照他们想要的方式进行组织(在一个名为“gh-的分支中”)页面“它应该工作正常。

You'll run into issues here if you have modules you depend on: You can either download all your dependencies (the stuff that you get when you run npm install or bower install , for example), or you can make sure all of the JavaScript files you reference are either in your repo or pointing at CDNs. 如果您有依赖的模块,那么您将遇到问题:您可以下载所有依赖项(例如,运行npm installbower install时获得的内容),或者您可以确保所有JavaScript您引用的文件位于您的仓库或指向CDN。

An example – instead of including this: 一个例子 - 而不是包括这个:

<script src="node_modules/angularjs/angularjs-1.5.4.min.js"></script>

You'd want this: 你想要这个:

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>

There are lots of places to find hosted versions of JS modules; 有很多地方可以找到JS模块的托管版本; Google is one, and CDN.js is handy as well. 谷歌就是其中之一, CDN.js也很方便。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM