React项目构建常用命令

1
2
3
4
5
6
7
8
//方法一:
npm install -g create-react-app//安装create-react-app
create-react-app hello-world-react//创建项目,项目名称不要有大写字母
npm run start 或者 npm start //进入项目目录后,启动项目
//方法二:
cnpm i yarn -g //提高安装react项目速度
npx create-react-app my-react //创建项目,项目名称不要有大写字母
npm run start 或者 npm start //进入项目目录后,启动项目

注意:启动项目后可能出现如下报错:

1
2
3
4
5
6
7
TypeError: MiniCssExtractPlugin is not a constructor

package.json里面:
"devDependencies": {
"mini-css-extract-plugin": "2.4.5"
}
导致

解决方案:

1
npm i -D --save-exact mini-css-extract-plugin@2.4.5