1.npm下载
到Node.js官网选择对应的版本进行安装
2.更换源为淘宝镜像
npm config set registry https://registry.npm.taobao.org
如果替换成功第二行会有字符串输出
3.配置全局模块路径和缓存
- 全局路径
npm config set prefix "D:\work\npm\node_global"
- 缓存路径
npm config set cache "D:\work\npm\node-cache"
- 配置环境变量
- 打开 我的电脑->属性->高级系统设置->环境变量
- 新建一个NODE_PATH 路径D:\work\npm\node_global\node_modules
- 将NODE_PATH添加到环境变量PATH中
- 添加D:\work\npm\node_global和D:\work\npm\node_module到PATH中
- 检测
npm install webpack -g
node
require('webpack')
- 不报错即配置成功