前端开发准备

90 阅读1分钟

安装NodeJs

  • Node.js 是一个基于 Chrome V8 引擎的 Javascript 运行环境

NodeJs官网下载最新的稳定版, 并安装

  1. NodeJs 安装
# NodeJs版本
> node -v
v16.15.0
# npm:包管理工具
#npm 版本
> npm -v 
8.5.5

安装Yarn

你可以认为 Yarn 是 npm 的增强版, 具体对比可以参考: Yarn vs npm

# 安装Yarn
> npm install --global yarn
# 查看当前安装的版本
> yarn -v
1.22.18

Yarn 源的管理

默认 Yarn 使用的是国外的源, 这对于国内开放者而言的体验是很差的(由于网速经常拉去不下来包), 因此我们需要切换源, 而 yrm 就是专门用于管理yarn源配置的工具, YARN registry manager (yrm):

# 安装yrm
> npm install -g yrm

# 查看yrm的版本
> yrm -V    
1.0.6

处理这样查看我们可以通过npm来查看当前系统上已经安装的全局工具:

> npm -g ls
C:\Users\80599\AppData\Roaming\npm
├── npx@10.2.2
├── yarn@1.22.19
└── yrm@1.0.6

查看当前有哪些可用的源

> yrm ls
* npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
  taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/
  yarn --- https://registry.yarnpkg.com

最后我们通过yrm来设置我们的源:

# 使用淘宝的源
> yrm use taobao
   YARN Registry has been set to: https://registry.npm.taobao.org/
   NPM Registry has been set to: https://registry.npm.taobao.org/

# 测试下淘宝源当前下载速度
> yrm test taobao
    * taobao - 273ms

npx安装

npm 从5.2版开始,增加了 npx 命令, 如果没有安装请手动安装:

# 查看当前npx版本
> npx -v
8.5.5
# 如果没有手动安装到全局
> npm install -g npx