我有一个使用 create-react-app 引导的 React 应用程序。该应用程序运行在docker容器中,并已部署在子域中。假设域名是 http://mycompany.com ,那么我的 React 应用程序位于 http://mycompany.com/users/userid/apps/reactapp 。
有一个反向代理服务器可以进行 URL 重写,将基本 URL 更改为子域 URL。这就是我的 package.json 的样子 -
{ "name": "my-app", "version": "0.1.0", "private": true, "dependencies": { "@material-ui/core": "^4.12.4", "@testing-library/jest-dom": "^5.16.1", "@testing-library/react": "^12.1.2", "@testing-library/user-event": "^13.5.0", "@types/classnames": "^2.3.1", "@types/jest": "^27.0.3", "@types/node": "^16.11.47", "@types/react": "^17.0.38", "@types/react-dom": "^17.0.11", "@types/react-icons": "^3.0.0", "@types/react-router-dom": "^5.3.2", "@types/sass": "^1.43.1", "bootstrap": "^5.1.3", "classnames": "^2.3.1", "font-awesome": "^4.7.0", "react": "^17.0.2", "react-dom": "^17.0.2", "react-icons": "^4.3.1", "react-router-dom": "^6.3.0", "react-scripts": "5.0.0", "register-service-worker": "^1.7.2", "typescript": "^4.5.4", "web-vitals": "^2.1.2" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }, "devDependencies": { "css-flatten": "^1.0.1", "react-hot-loader": "^4.13.1", "react-select": "^5.4.0", "sass": "^1.45.2" } }
我面临的问题是,即使在我使用react-scripts start重新启动开发服务器后,任何JS文件更改都不会得到反映。仅当我重新启动 docker 容器时才会反映出来。在浏览器中,我检查过,bundle.js 文件没有最新的更改。我已经尝试过这些事情 -
我可以在开发服务器日志中看到,正在检测到文件更改,但这些更改并不用于提供给浏览器。即使我删除了一个文件(因此我可以在开发服务器日志中看到错误日志),但即使浏览器刷新,应用程序仍然没有任何更改。
您可能需要将以下内容添加到服务器端响应标头
如果问题仍然存在,您可以尝试清除浏览器缓存
相关问题: