【问题标题】:React images not loading locally after gh-pages installation安装 gh-pages 后反应图像未在本地加载
【发布时间】:2022-01-10 22:53:17
【问题描述】:

我正在尝试在 gh-pages 上部署一个 react 应用程序并且我已经成功完成了,但是在部署之后我确实在本地服务器上再次运行了该应用程序以添加一些新功能,我看到它没有加载图像之前加载过。

{
  "name": "react-tesla-clone",
  "homepage": "https://elbeicktalat.github.io/react-tesla-clone",
  "version": "0.1.0",
  "private": true,
  "dependencies": {...},
  "scripts": {
    "predeploy": "yarn run build",
    "deploy": "gh-pages -d build",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "gh-pages": "^3.2.3"
  }
}

在 gh-pages 设置之前

在 gh-pages 设置之后

那么解决办法是什么?

【问题讨论】:

    标签: reactjs web deployment github-pages


    【解决方案1】:

    所有这些都是由 package.json 主页属性引起的,事实上如果你删除它你会解决这个问题,但是每次你想在本地运行项目时删除它并不是最好的主意。

    那么我们可以做些什么呢? 非常简单,只需在项目根文件夹中创建.env 文件并在其中添加以下内容:

    PUBLIC_URL="."
    

    【讨论】:

      猜你喜欢
      • 2015-12-13
      • 1970-01-01
      • 1970-01-01
      • 2022-10-07
      • 1970-01-01
      • 1970-01-01
      • 2020-08-11
      • 1970-01-01
      • 2017-12-11
      相关资源
      最近更新 更多