如何在没有Node服务器的情况下运行AngularJS2应用程序 [英] How to run AngularJS2 application without Node server

查看:87
本文介绍了如何在没有Node服务器的情况下运行AngularJS2应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在浏览器中运行Angular 2应用程序而不使用NodeJS作为服务器。我不确定,但如果我理解正确,最新的浏览器能够编译/理解TypeScript代码,所以我不必使用任何第三部分js lib将其编译成普通的javascript?

Is it possible to run an Angular 2 application in browser without using NodeJS as a server. I am not sure, but if i understand correctly the newest browsers are able to compile/"understand" the TypeScript code so i don't have to use any third part js lib to compile it into plain javascript?


我想在前端创建一个使用100%Angular 2的应用程序,使用Ruby On Rails创建
后端REST API,而不使用Rails的页面渲染,会话等..

I would like to create an application using 100% Angular 2 on frontend and for the backend REST API using Ruby On Rails, without using Rails's page rendering, sessions etc..

我对它如何在幕后工作/运行时感到困惑......我应该如何配置我的Angular2应用程序在没有NodeJS的情况下使用它?

I am little confused about it how does Angular2 work/run behind the scenes... How i should configure my Angular2 application to use it without NodeJS?

推荐答案

我认为你在这里混淆了一些技术。

I think you're mixing up some technologies here.

服务器

您可以在任何可以托管静态文件的服务器上运行Angular应用程序。节点没有什么特别之处。所以,是的,你可以使用红宝石。或Apache,nginx,lighttpd等。

You can run an Angular app on any server that can host static files. There is nothing special about node. So yes, you can use a ruby. Or an Apache, nginx, lighttpd etc.

原因是JavaScript在客户端运行。服务器的响应只是将JS / HTML / CSS文件传递给访问您网站的客户端。

The reason for this is that JavaScript is run on the client side. The server's response is only to deliver the JS/HTML/CSS files to the client that is visiting your site.

TypeScript

如果您正在使用TypeScript编写应用程序,则需要在任何浏览器理解之前将其转换为JavaScript。您可以在将应用程序部署到服务器之前执行此操作(1),或者(2)使用系统等库。 js 将动态地转换TypeScript。

If you're writing an application with TypeScript you need to transpile it to JavaScript before any browser understands it. You can do this (1) before you're deploying your app to the server or (2) use a library like System.js that will transpile TypeScript on the fly.

虽然(2)绝对是一个选项而且 Angular CLI 直到最近使用它,(1)在我看来是更好的选择。 Angular CLI切换到(1),现在使用 webpack 。 Webpack正在转发并捆绑您的应用程序,然后将其托管在服务器上。

While (2) is definitely an option and the Angular CLI used it until recently, (1) is in my opinion the better option. Angular CLI switched to (1) and is now using webpack. Webpack is transpiling and bundling your app before it is hosted on a server.

希望我能为您解决一些问题。

Hope I could clear things up a bit for you.

这篇关于如何在没有Node服务器的情况下运行AngularJS2应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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