0

我在 GitLab 页面上部署 Vue js(在子目录 ex:/front-end/admin-dashboard 上),但是当我打开 URL 时,我收到了资产的 404 错误。

这是我的 GitLab ci:

pages: # the job must be named pages
  image: node:latest
  stage: deploy
  script:
    - npm install --force
    - npm run build
    - mv public public-vue # GitLab Pages hooks on the public folder
    - mv dist public # rename the dist folder (result of npm run build)
    # optionally, you can activate gzip support with the following line:
    - find public -type f -regex '.*\.\(htm\|html\|txt\|text\|js\|css\)$' -exec gzip -f -k {} \;
  artifacts:
    paths:
      - public # artifact path must be /public for GitLab Pages to pick it up
  only:
    - master

这是vue.config.js


module.exports = {
  publicPath: process.env.NODE_ENV === 'production' ? `/${process.env.CI_PROJECT_NAME}/` : '/',
  transpileDependencies: ['vuetify'],
};

在此处输入图像描述

注意:我的路由器模式是“历史”。

这是serviceWorker.js

/* eslint-disable no-console */

import { register } from 'register-service-worker';

if (process.env.NODE_ENV === 'production') {
  register(`${process.env.BASE_URL}service-worker.js`, {
    ready() {
      console.log(
        'App is being served from cache by a service worker.\n',
      );
    },
    registered() {
      console.log('Service worker has been registered.');
    },
    cached() {
      console.log('Content has been cached for offline use.');
    },
    updatefound() {
      console.log('New content is downloading.');
    },
    updated() {
      console.log('New content is available; please refresh.');
    },
    offline() {
      console.log('No internet connection found. App is running in offline mode.');
    },
    error(error) {
      console.error('Error during service worker registration:', error);
    },
  });
}

4

1 回答 1

0

如果您的项目位于组中,例如mygroup.gitlab.io/myusername/myprojectname

您可以将此代码添加到vue.config.js文件中:

module.exports = {
    publicPath: '/myusername/myprojectname/'
}

如果这是正确的答案,请接受或评论:) 谢谢

于 2021-07-08T07:12:04.730 回答