react中自定义配置文件
在已有的项目中运行:npm run eject
如果报错,就先运行:
git add .
git commit -m 'init'
再执行npm run eject
这时在你的项目中就会生成config文件夹,可以根据自己的需要修改配置
删除node_modules文件夹的内容,冲刺你安装 npm install
修改端口号:
scripts->start.js
关闭eslint
在config-》webpack.config.js
module-》rules中
设置路径别名:
config->webpack.config.js
resolve=>alias
静态资源配置
create-react-app public文件存放静态资源
请求代理proxy
2.0以上的版本,package.json中添加字符串
"proxy": "http://localhost:4000",
这样,当你在开发中使用 fetch(’/api/todos’) 时,开发服务器将识别出它不是静态资源,并将你的请求代理到http://localhost:4000/api/todos 作为后备。开发服务器将 仅仅 尝试将 Accept 头中没有 text/html 的请求发送到代理。
参考:https://blog.csdn.net/hbiao68/article/details/101215029