用gh-pages构建反应生成静态文件的错误文件路径

时间:2019-12-10 16:37:53

标签: reactjs build github-pages

各位程序员好!

我正在npm库gh-pages的帮助下部署应用程序。我遇到的问题是我的构建文件夹中的index.html将我的存储库名称错误地添加到了静态文件路径中。

根据文档,我package.json中的homepage字段应如下所示

"homepage": "https://username.github.io/repoName/",

但是,当我输入网站URL时,我会得到404错误代码,因为它正在寻找我的静态文件

"/repoName/static/js/main.34abd32a.chunk.js"

这让我感到困惑,因为我需要保持主页字段的原样才能将其推送到gh-pages分支。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,静态文件被用作<Window x:Class="WpfWebView2TEST.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> </Grid> </Window> ,这是无效的。正确的是extension ViewController: UIScrollViewDelegate { import UIKit class ViewController: UIViewController, UIScrollViewDelegate { @IBOutlet weak var label: UILabel! override func viewDidLoad() { super.viewDidLoad() scrollView.maximumZoomScale = 4 scrollView.minimumZoomScale = 1 scrollView.delegate = self } @IBAction func randomWord(_ sender: Any) { let array = ["Dam", "Military Base", "Quarry", "Airport", "Tv Station", "Storage Town", "Superstore", "Stadium", "Lumber", "Boneyard", "Train Station", "Hospital", "Downtown", "Farmland", "Promenade East", "Promenade West", "Hills", "Park", "Port", "Prison"] label.text = array.randomElement() } @IBOutlet weak var scrollView: UIScrollView! @IBOutlet weak var mapImage: UIImageView! extension ViewController: UIScrollViewDelegate { func viewForZooming(in scrollView: UIScrollView) -> UIView? { return mapImage } } }

我已经使用repo-name/static/..和gh-pages(https)和来自Google域的自定义域创建了应用

我通过以下步骤解决了

  1. 在package.json /static/..中(请不要在此处使用仓库名称)
  2. 使用npx create-react-app"homepage": "https:/username.github.io" index.js。以下是我的代码段

BrowserRouter