vite+vue3 打包后页面空白现象

发布时间 2023-12-27 14:05:23作者: 落子戏

使用vite打包之后运行index.html空白,打开控制台发现报错:

解决方法:

  在vite.config中加入:

 publicPath: './',

  这是vite.config中的结构:

 
export default defineConfig({
  publicPath: './',
  lintOnSave: false,
  transpileDependencies: true,
  plugins: [
    vue(),
  ],
  server: {
    host: '0.0.0.0'
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})

 打包之后的html

  
<script type="module" crossorigin src="./assets/xxx.js"></script>
<link rel="stylesheet" crossorigin href="./assets/xxx.css">