Vite构建vue项目开启打包后本地方法能力

Vite构建vue项目开启打包后本地方法能力

node.js v20.0+

vite v5.2+

问题1:项目打包后 服务器访问空白

问题2:项目打包后 本地访问空白

问题3:项目打包后https访问空白

问题4:项目打包后子域名(www.xxx.xx)访问空白

解决办法如下:在项目vite.config.js文件中配置如下

**(必须)打包后的文件 dist/index.html 去除所有存在的 type=”module” 去除 crossorigin 去除 nomodule

////vite.config.js
import { defineConfig } from "vite";
import legacy from "@vitejs/plugin-legacy"; //必须
import vue from '@vitejs/plugin-vue' 

export default defineConfig({
  base: "./",//必须
  plugins: [
    vue(),
    legacy({
      targets: ["ie>=11"],
      additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
    }),
  ],
});
260 Views
分享你的喜爱
linwute
linwute

我要像梦一样自由,像大地一样宽容;
在艰辛放逐的路上,点亮生命的光芒;
我要像梦一样自由,像天空一样坚强;
在曲折蜿蜒的路上,体验生命的意义;

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注