ReactJS构build文件的资源path
我有一个ReactJS项目,生成npm run build
后的服务的静态文件。 这些文件是一个index.html
, main.ef19974a.js
和main.f06643f6.css
。
该html
文件具有对这些其他文件的引用,但是作为绝对path。 这意味着当客户端服务于html
文件时,它会尝试在主机上search/static/js/main.ef19974a.js
,而不是从index.html
目录searchstatic/js/main.ef19974a.js
index.html
文件正在上传。
有没有办法使React在构build步骤中创build相对path引用,还是允许我们提供工作目录?
临时工作的解决方法是手动修改生成的index.html
文件以引用js
和css
文件,但是当我包含其他资源( index.html
从index.html
引用的图像并且默认返回到这些文件的绝对path)时会失败。
您可以使用homepage
键在package.json
设置包含index.html
的文件夹:
... "devDependencies": { "react-scripts": "1.0.10" }, "homepage": "/myapp", // website will be hosted at http://hostname/myapp "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "toolbox": "react-toolbox-themr", "eject": "react-scripts eject" }, ...