1、安装nodejs

1
2
3
wget https://nodejs.org/dist/v8.11.3/node-v8.11.3-darwin-x64.tar.gz
tar -xvf node-v8.11.3-darwin-x64.tar.gz
ln -s node-v8.11.3-darwin-x64 node
1
vi /etc/profile
1
2
export NODE_HOME=/data/node
export PATH=$NODE_HOME/bin:$PATH
1
2
3
source /etc/profile
node -v
npm -v

2、npm

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
## 更新npm
npm install npm@latest -g
## 更换npm仓库
## 临时更换npm镜像
npm --registry https://registry.npm.taobao.org install express
## 永久更换npm镜像
npm config set registry https://registry.npm.taobao.org
## 查看npm所有config
npm config list --json
## 创建
npm init -y
## 安装依赖
npm install <package_name> --save
npm install <package_name> --save-dev
npm install <package_name>
## 执行命令
## 对应package.json中scripts下的指令
npm run <cmd>
# 自动化构建工具
npm install -g grunt
npm install -g gulp
npm install -g brunch
# 预编译的模块化(让浏览器识别 define、exports、module )、打包
npm install --save-dev webpack
# 预编译,把ES6、ES7、ES8等高级语法 编译为浏览器兼容的低版语法
npm install --save-dev babel-cli babel-preset-es2015
npm install --save-dev eslint babel-eslint
# node进程管理
npm install pm2 -g
pm2 install pm2-hooks
pm2 install pm2-githook
1
2
## 配置依赖
vi package.json:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
"devDependencies": {
  "babel-core": "^6.14.0",
  "babel-loader": "^6.2.5",
  "babel-preset-es2015": "^6.18.0",
  "vue-loader": "^10.0.2",
  "eslint": "^3.5.0",
  "serve": "^1.4.0",
  "webpack": "^1.13.2",
  "weex-loader": "^0.3.3",
  "weex-builder": "^0.2.6"
},
"dependencies": {
  "weex-html5": "^0.3.2",
  "weex-components": "*"
}

3、其他

1
2
3
4
5
# nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
nvm install 10.15.0
# yarn
curl -o- -L https://yarnpkg.com/install.sh | bash

4、参考