- 安装 create-react-app,已经安装过的请略过。
npm install -g create-react-app 或者用yarn,cnpm 安装都可以
- 创建项目
create-react-app react-mobx-demo
- 安装依赖
yarn add mobx mobx-react react-app-rewired --save-dev
- 运行eject
git add .
git commit -am "Save before ejecting"
npm run eject
- 安装bable依赖
yarn add @babel/core @babel/plugin-proposal-class-properties @babel/plugin-proposal-decorators --save-dev
- 修改 package.json 里的启动配置
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js"
},
"babel": {
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
]
],
"presets": [
"react-app"
]
}
按照顺序执行下来,最后启动项目即可。