gpt4 book ai didi

reactjs - 将 React 应用程序部署到 gitlab 页面后出现空白页面

转载 作者:行者123 更新时间:2023-12-05 03:41:28 25 4
gpt4 key购买 nike

我想将我的 React 应用程序(不是 create-react-app,从 skratch 构建)部署到 gitlab 页面,所有作业都成功通过,但页面无法正常工作。我只有一张空白的白页。

我的.gitlab-ci.yml

stages:
- build
- deploy

build:
image: node:latest
stage: build
script:
- npm install
- npm run build
artifacts:
paths:
- build/

pages:
image: alpine:latest
stage: deploy
variables:
GIT_STRATEGY: none
script:
- mv build public
- cd public
artifacts:
paths:
- public

我的 webpack,我将 common 与 prod 合并

webpack.common.js


module.exports = {
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
entry: {
index: './src/index.tsx'
},
output: {
filename: "[name].[chunkhash].js",
chunkFilename: "[name].[chunkhash].js",
path: path.resolve(__dirname, "public"),
publicPath: "/"
},
plugins: [
new MiniCssExtractPlugin({ filename: '[name].[contenthash].css', chunkFilename: '[name].[contenthash].css' }),
new HtmlWebpackPlugin({
template: "src/index.html",
inject: "body",
minify: {
minifyCSS: true,
minifyJS: true,
collapseWhitespace: true
}
}),
],
module: {
rules: [
{
test: /\.(css|scss|sass)$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
},
{
test: /\.(png|svg|jpg|gif)$/i,
use: ['file-loader']
},
{
test: /\.html$/,
use: [{ loader: 'html-loader' }]
},
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /(node_modules|bower_components|prod)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript']
}
}
}
]
}
}

webpack.prod.js

module.exports = merge(common, {
mode: 'production',
optimization: {
minimizer: [
new UglifyJsPlugin({
test: /\.js(\?.*)?$/i,
})],
moduleIds: 'deterministic',
runtimeChunk: 'single',
splitChunks: {
name: 'runtime',
chunks: 'all'
}
}
})

包.json

    "scripts": {
"start": "webpack-dev-server --config webpack.dev.js --open",
"build": "webpack --config webpack.prod.js"
},

正如我提到的,在本地工作正常,无论是开发服务器还是构建。

我没有控制台错误,只是一个警告:

Error with Permissions-Policy header: Unrecognized feature:'interest-cohort'.

Cross-Origin Read Blocking (CORB) blocked cross-origin responsehttps://gitlab.com/users/sign_in with MIME type text/html. Seehttps://www.chromestatus.com/feature/5629709824032768 for moredetails.

我注销了,当我登录时我得到 401err

GET https://projects.gitlab.io/auth?code=2.... net::ERR_ABORTED 401

项目是公开的

最佳答案

遇到了同样的问题。结果 package.json 中的 homepage 属性包含不正确的站点 url。

您需要在 package.json 的顶部添加此属性(如果尚未添加),并确保它指向您站点的 gitlab 页面 url。

{
"homepage": "GITLAB_PAGES_URL",
"name": "...",
...
}

关于reactjs - 将 React 应用程序部署到 gitlab 页面后出现空白页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67738161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com