gh页无法从index.html加载bundle.js

时间:2019-03-29 06:42:40

标签: reactjs webpack github-pages html-webpack-plugin

我已经使用webpack设置了一个React项目。我想将该项目上传到我在Github上的用户站点上。 我创建了具有两个分支的用户站点存储库-mastergh-pages。 项目结构如下:

 dist
    index.html
    bundle.js
 index.html

Package.json文件具有以下用于构建和部署的命令。

 "start": "webpack-dev-server --open --mode development --content-base ./dist",
 "test": "npm run lint && npm run security-check && npm run bundle",
 "predeploy": "npm run build",
 "deploy": "gh-pages -d dist"

在开发模式下,项目运行正常。HtmlWebPackPlugin正在将bundle js脚本标记插入dist/index.html中。 为了部署到gh-pages,当我运行deploy命令时,代码会在分支gh-pages中正确更新。我可以在其中看到最新的dist文件夹文件。

但是用户站点给我404: not found error的{​​{1}}。

1 个答案:

答案 0 :(得分:0)

因此,在对gh页进行了一些研究之后,我找到了解决方案。 对于用户页面,Github仅允许从private class HomePageAdapter(private val layoutInflater: LayoutInflater, fragmentManager: FragmentManager) : NoMiddleFragmentPagerAdapter(fragmentManager) { override fun getLeftItem(): Fragment = LeftFragment() override fun getRightItem(): Fragment = RightFragment() override fun instantiateCentralArea(container: ViewGroup, position: Int): Any { val view = layoutInflater.inflate(R.layout.main_content_area, container, false) container.addView(view) return view } } 分支发布。因此masterindex.html应该存在于master分支中,它们将被用作静态资源。

这有点令人困惑 在其他应用中,您可以选择从master或gh-pages分支或/ docs目录中进行构建。

因此,我创建了一个bundle.js分支,我的原始代码仍在其中。 然后,我修改了deploy命令,将代码从development分支上传到development

master
相关问题