Javascript 开发环境

最佳实践 5 分钟阅读 更新于 2024-11-06

1. Overview

Windows Linux/WSL

2. Windows

2.1. fnm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 安装
# https://github.com/Schniz/fnm?tab=readme-ov-file#installation
winget install -e --id Schniz.fnm
# or using cargo if you have rust installed
# cargo install fnm

# 更新 $PROFILE
Add-Content -Path $PROFILE -Value @'
# fnm
$env:FNM_NODE_DIST_MIRROR = "https://mirrors.aliyun.com/nodejs-release/"
fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression
$env:ELECTRON_MIRROR = "https://npmmirror.com/mirrors/electron/"

'@

# 安装 node (open in a new terminal tab)
fnm use --install-if-missing 22

# 设置 npm 源
npm config set registry https://registry.npmmirror.com

2.2. bun

安装

1
powershell -c "irm bun.sh/install.ps1|iex"

设置国内源

1
2
3
4
Add-Content -Path $PROFILE -Value @'
$env:BUN_CONFIG_REGISTRY = "https://registry.npmmirror.com"

'@

3. Linux/WSL

3.1. fnm

安装

1
curl -fsSL https://fnm.vercel.app/install | bash

设置国内源

for bash

$HOME/.bashrc

1
2
3
export FNM_NODE_DIST_MIRROR="https://mirrors.aliyun.com/nodejs-release/"
export ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"
export COREPACK_NPM_REGISTRY="https://registry.npmmirror.com"

for fish

$HOME/.config/fish/conf.d/fnm.fish

1
2
3
set -x FNM_NODE_DIST_MIRROR "https://mirrors.aliyun.com/nodejs-release/"
set -x ELECTRON_MIRROR "https://npmmirror.com/mirrors/electron/"
set -x COREPACK_NPM_REGISTRY "https://registry.npmmirror.com"

打开新终端

1
2
3
4
5
6
7
8
9
# 安装 node (open in a new terminal tab)
fnm use --install-if-missing 24

# 设置 npm 源
npm config set registry https://registry.npmmirror.com

# enable pnpm
corepack enable pnpm
pnpm setup

3.2. bun

安裝

1
curl -fsSL https://bun.com/install | bash

设置国内源

for bash

$HOME/.bashrc

1
export BUN_CONFIG_REGISTRY="https://registry.npmmirror.com"

for fish

$HOME/.config/fish/config.fish

1
set -x BUN_CONFIG_REGISTRY "https://registry.npmmirror.com"
标签: xops js

如果这篇文章对您有帮助,欢迎打赏支持