【发布时间】:2022-01-12 11:20:50
【问题描述】:
我正在尝试在 Github 页面上部署一个带有 Parcel 的 React 应用程序。
我已经部署了它,但应用程序实际上并没有在屏幕上呈现。我不明白我做错了什么。
包.json
{
"name": "pet-adoption-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"homepage": "https://github.com/junaidshaikh-js/pet-adoption-app",
"scripts": {
"format": "prettier --write \"src/**/*.{js,jsx}\"",
"lint": "eslint \"src/**/*.{js,jsx}\" --quiet",
"dev": "parcel src/index.html --public-url /pet-adoption-app/",
"predeploy": "npm build",
"deploy": "gh-pages -d dist"
},
"repository": {
"type": "git",
"url": "git+https://github.com/junaidshaikh-js/pet-adoption-app.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/junaidshaikh-js/pet-adoption-app/issues"
},
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.13.4",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-transform-runtime": "^7.16.4",
"@babel/preset-env": "^7.13.5",
"@babel/preset-react": "^7.12.13",
"eslint": "^8.3.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"gh-pages": "^3.2.3",
"parcel": "^1.12.3",
"prettier": "^2.4.1"
},
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0"
}
}
这是实时部署的链接:https://junaidshaikh-js.github.io/pet-adoption-app/
这里是 Github 仓库:https://github.com/junaidshaikh-js/pet-adoption-app
【问题讨论】:
-
脚本和样式未发布。看起来服务器上只有 index.html 。 Parcel 必须构建所有内容,因为文件名已损坏,但文件根本不存在。
-
我该如何解决?
-
gh-pages命令将你的 dist 发布到你的 repo 的 gh-pages 分支。您是否将此分支设置为此 repo 中 GitHub Pages 的“源”?转到设置>页面进行验证。 -
是的,这是源分支
-
问题在于,在 index.html(已发布的)中,您的 CSS 和 JS 文件与这样的路径链接:
/style.e308ff8e.js,也就是说它们是预期的位于根文件夹中。但是你的应用的 URL 是 junaidshaikh-js.github.io/pet-adoption-app,所以 index.html ,所有的 CSS 和 JS 文件都位于 /pet-adoption-app 文件夹。您需要配置 Parcel,以便它将该相对路径添加到所有链接。
标签: reactjs deployment github-pages parceljs