GitHub:https://github.com/Justin-Schneider/portfolio
链接到页面:https://justin-schneider.github.io/portfolio/
链接没有任何结果,我得到以下两个错误:
GET https://justin-schneider.github.io/portfolio/justin-schneider.github.io/portfolio/static/css/main.233e2870.css net::ERR_ABORTED
GET https://justin-schneider.github.io/portfolio/justin-schneider.github.io/portfolio/static/js/main.c60b5716.js net::ERR_ABORTED
npm run deploy正确执行
的package.json
{
"name": "my-website",
"version": "0.1.0",
"private": true,
"homepage": "justin-schneider.github.io/portfolio",
"dependencies": {
"react": "^16.2.0",
"react-bootstrap": "^0.31.5",
"react-dom": "^16.2.0",
"react-scripts": "1.0.17"
},
"scripts": {
"deploy" : "npm run build&&gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"gh-pages": "^1.1.0"
}
}
在您的nodejs中确保您将构建文件夹设置为静态,以便可以从浏览器访问它
app.use(express.static('./client/build/'));
app.use('/', express.static('./client/build/index.html'));
似乎在你的react-scripts build
反应是建立相对路径,因此引用错误的https://justin-schneider.github.io/portfolio/justin-schneider.github.io/portfolio/static/css/main.233e2870.css
而不是你正确的网址:https://justin-schneider.github.io/portfolio/static/css/main.233e2870.css
。如果你不能在react-build中更改css和js的dist路径,你可以考虑使用https://webpack.js.org/作为css和js bundler,在那里你可以设置你的静态目录选项,你可以正确地引用它们。
在我的package.json中我需要“https://justin-schneider.github.io/portfolio”而不仅仅是“justin-schneider.github.io/portfolio”
我更新的package.json
{
"name": "my-website",
"version": "0.1.0",
"private": true,
"homepage": "https://justin-schneider.github.io/portfolio",
"dependencies": {
"react": "^16.2.0",
"react-bootstrap": "^0.31.5",
"react-dom": "^16.2.0",
"react-scripts": "1.0.17"
},
"scripts": {
"deploy" : "npm run build&&gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"gh-pages": "^1.1.0"
}
}