1.在官网下载安装包https://nodejs.org/en/download/
2.安装
3.配置cache和全局目录,在windows上新建两个目录,然后在cms中设置
npm config set cache "D:Program Files odejs ode_cache" npm config set prefix "D:Program Files odejs ode_globall"
4.设置环境变量
系统变量中添加NODE_PATH
D:Program Files odejs ode_global
系统变量的path变量中新增
D:Program Files odejs
%NODE_PATH%
D:Program Files odejs ode_global ode_modules
5.安装cnpm 淘宝源
npm install -g cnpm --registry=https://registry.npm.taobao.org
6.测试
cnpm -V
出现以下界面则安装成功
cnpm@6.1.1 (D:Program Files odejs ode_global ode_modulescnpmlibparse_argv.js) npm@6.14.2 (D:Program Files odejs ode_global ode_modulescnpm ode_modules pmlib pm.js) node@12.16.1 (D:Program Files odejs ode.exe) npminstall@3.27.0 (D:Program Files odejs ode_global ode_modulescnpm ode_modules pminstalllibindex.js) prefix=D:Program Files odejs ode_global win32 x64 10.0.18362 registry=https://r.npm.taobao.org
7.安装@vue/cli
cnpm install -g @vue/cli
8.测试
vue -V
9.建立测试项目
vue init webpack-simple test
提示:
Command vue init requires a global addon to be installed. Please run npm install -g @vue/cli-init and try again.
安装
cnpm install -g @vue/cli-init
再次建立项目
运行
npm run dev
报错:
> test@1.0.0 dev E:VueProjects est > cross-env NODE_ENV=development webpack-dev-server --open --hot 'cross-env' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! test@1.0.0 dev: `cross-env NODE_ENV=development webpack-dev-server --open --hot` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the test@1.0.0 dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install? npm ERR! A complete log of this run can be found in: npm ERR! D:Program Files odejs ode_cache\_logs2020-03-15T14_06_10_798Z-debug.log
原因:这是新版webpack存在的BUG,卸载现有的新版本webpack,装老版本就好。
(1)、npm uninstall webpack-dev-server
(2)、npm install webpack-dev-server@2.9.1
(3)、npm run dev
运行成功!