Goo*_*Guy 5 gitlab reactjs gitlab-ci
我想将我的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
Run Code Online (Sandbox Code Playgroud)
我的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']
}
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
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'
}
}
})
Run Code Online (Sandbox Code Playgroud)
包.json
"scripts": {
"start": "webpack-dev-server --config webpack.dev.js --open",
"build": "webpack --config webpack.prod.js"
},
Run Code Online (Sandbox Code Playgroud)
正如我提到的,开发服务器和构建在本地工作正常。
我没有控制台错误,只有警告:
Permissions-Policy 标头错误:无法识别的功能:“interest-cohort”。
和
跨源读取阻止 (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
项目是公开的
有同样的问题。结果 homepage属性中package.json包含不正确的站点 URL。
您需要在 的顶部添加此属性(如果尚未添加)package.json,并确保它指向您站点的 gitlab 页面 url。
{
"homepage": "GITLAB_PAGES_URL",
"name": "...",
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1780 次 |
| 最近记录: |