下载地址:https://nodejs.org/en/download/
通过再命令行里输入node -v
,npm -v
来查看node和npm是否安装好
使用NPM配置React开发环境
如何用NPM包来初始化react项目
1、初始化
npm init
在entry point: (index.js) index.js
填写index.js
{
"name": "05-01",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
项目依赖包安装
1、安装react DOM
在cmd下进入文件目录,输入npm install --save react react-dom babel-preset-react
2、安装ES2015/ES6
继续在cmd命令行中输入,npm install babel-preset-es2015 --save
"--save"的作用是为了把配置保存到配置文件中去
所有的包都会放在
node_modules
文件夹中,用npm安装包,方便对包的管理
3、查看已安装的包和对应版本
只需要打开
pakage.json
文件{ "name": "05-01", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "antd": "^3.2.2", "babel-core": "^6.26.0", "babel-loader": "^7.1.2", "babel-preset-es2015": "^6.24.1", "babel-preset-react": "^6.24.1", "react": "^16.2.0", "react-dom": "^16.2.0", "react-mixin": "^2.0.2", "webpack": "^3.11.0", "webpack-dev-server": "^2.11.1" } }
4、批量导入安装包
1、在pakage.json
里直接输入安装包名和对应版本
2、删除node_modules
文件夹
3、运行命令npm install
5、上传git的时候可以把node_modules
文件夹删除,配置只需要看package.js
就可以