react项目build后部署在tomcat非root目录下

使用create-react-app手脚架生成项目后,发布的时候发现找不到文件,打包的路径不对

两种方法:

第一种:

找到当前项目路径下:例如:first_react_app\node_modules\react-scripts\config
更改path.js文件,大约在46行左右,将路径更改为要发布的路径“/react”;

第二种:

在package.json中增加一个homepage字段,如下

{
  "name": "first_react_app",
  "version": "0.1.0",
  "private": true,
  "homepage": "/react",  //打包的路径
  "dependencies": {
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts": "2.1.8"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

你可能感兴趣的:(react项目build后部署在tomcat非root目录下)