简体   繁体   中英

How to run AngularJS2 application without Node server

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?

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..

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.

Server

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.

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

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.

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.

TL;DR

If you use TypeScript with Angular 2, you only need Node during development:

DEV : NodeJS is used to transpile .ts files to .js files.

PROD : Generated .js files are used inside the browser , NodeJS is not required anymore, except if you also happen use it in the backend.

NOTE : If you only use plain JS in development you do not even need Node

You can use any server side technology including Asp.Net Core, Node.Js, PHP to server the js, html and css content.

While building the application in the IDE, the Node.js transpile the .ts files into .js file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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