likes
comments
collection
share

vue(vite/webpack)项目打包后部署到gitee报404问题

作者站长头像
站长
· 阅读数 307

使用vite创建

使用vite创建的vue3项目,如果打包完后想部署到gitee上,会显示空白,并且控制台报404错误

vue(vite/webpack)项目打包后部署到gitee报404问题

遇到这种问题,需要在vite.config.js里的配置项添加一个base属性

vue(vite/webpack)项目打包后部署到gitee报404问题

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
  //部署git配置路径,否则报404
  base: "./",
  plugins: [vue()],
});

使用webpack创建

需要在vue.config.js里添加publicPath

vue(vite/webpack)项目打包后部署到gitee报404问题

const BASE_URL = process.env.NODE_ENV === 'production' ? '/项目目录/' : '/'

module.exports = {
  lintOnSave:false,
  publicPath:BASE_URL,
}