簡體   English   中英

將反應應用程序部署到 gitlab 頁面后得到一個空白頁面

[英]Got a blank white page after deploying react app to gitlab pages

我想將我的 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 ,我與 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'
        }
    }
})

package.json

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

正如我提到的本地工作正常,開發服務器和構建。

我沒有控制台錯誤,只是一個警告:

權限策略 header 出錯:無法識別的功能:“興趣隊列”。

跨域讀取阻塞 (CORB) 阻止了 MIME 類型 text/html 的跨域響應https://gitlab.com/users/sign_in 有關詳細信息,請參閱https://www.chromestatus.com/feature/5629709824032768

我退出了,當我登錄時我得到 401err

獲取https://projects.gitlab.io/auth?code=2...。 凈::ERR_ABORTED 401

項目是公開的

有同樣的問題。 原來package.json中的homepage屬性包含不正確的站點 url。

You need to add this attribute (if not already) at the top of package.json , and make sure it is pointing to the gitlab pages url for your site.

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM