为什么我们要为Angular 2.0安装Node.js? [英] Why do we have install Node.js for Angular 2.0?

查看:228
本文介绍了为什么我们要为Angular 2.0安装Node.js?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Angular 2.0开始了一个教程,设置工作区的第一步是安装Node.js和NPM.

为什么要为Angular 2.0安装Node.js?

我不记得要在1.X角上这样做.

解决方案

技术上,不需要Angular2即可使用Node.js和NPM.它确实使事情变得轻松.这是我推测此选择背后的主要原因:

  • CLI :一段时间以来,构建和开发新Angular应用程序的实际方法是使用 CLI工具,它也依赖于Node和NPM.

  • TypeScript :示例是.ts,您需要运行一个编译器步骤才能将它们导入.js,使用Node.js和NPM(加上这是一种轻松键入文件的方式);

  • Web服务器:通过轻量级的Web服务器为真实"的Angular SPA提供服务,可以防止使用file://链接检查站点时可能出现的一些讨厌的问题.

快速入门"指南本身实际上也继续提到了一些更具体的原因:

以下是这些脚本的作用:

  • npm start-在监视模式"下同时运行编译器和服务器

  • npm run tsc-一次运行TypeScript编译器

  • npm run tsc:w-在监视模式下运行TypeScript编译器;该过程一直在运行,等待对TypeScript文件的更改并在看到它们时重新编译

  • npm run lite-运行lite-server,这是一种轻量级的静态文件服务器,对使用路由的Angular应用程序具有出色的支持

  • npm run typings-单独运行打字工具

  • npm run postinstall-成功完成软件包安装后,由npm自动调用.该脚本安装在types.json

  • 中定义的TypeScript定义文件.

您还可以查看快速入门源,并进一步深入了解需要NPM的地方.


脚注:还有一个类似的问题,关于需要将Node.js用于AngularJS(1.x).

I started a tutorial on Angular 2.0, the first step in setting up the workspace is installing Node.js and NPM.

Why do we have install Node.js for Angular 2.0?

I don't remember doing this for angular 1.X.

解决方案

Technically, Node.js and NPM are not needed to do Angular2 work. It does ease things though. Here's the main reasons I speculate are behind this choice:

  • CLI: Since a while now the de facto way to build and develop new Angular apps is to use the CLI tooling which relies on Node and NPM as well.

  • TypeScript: Examples are .ts, and you need to run a compiler step to get them into .js, which can be done on-the-fly easily with Node.js and NPM (plus it's a way of easily getting typing files);

  • Web Server: Serving your Angular SPA from a "real" albeit light web server prevents probably some nasty issues that come with checking your site using file:// links.

The Quickstart guide itself actually continues to mention some more concrete reasons as well:

Here's what these scripts do:

  • npm start - runs the compiler and a server at the same time, both in "watch mode"

  • npm run tsc - runs the TypeScript compiler once

  • npm run tsc:w - runs the TypeScript compiler in watch mode; the process keeps running, awaiting changes to TypeScript files and re-compiling when it sees them

  • npm run lite - runs the lite-server, a light-weight, static file server with excellent support for Angular apps that use routing

  • npm run typings - runs the typings tool separately

  • npm run postinstall - called by npm automatically after it successfully completes package installation. This script installs the TypeScript definition files defined in typings.json

You can also have a look at the Quickstart source and further dive into where NPM is needed.


Footnote: there's a similar question about needing Node.js for AngularJS (1.x).

这篇关于为什么我们要为Angular 2.0安装Node.js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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