Browse Source

feat: 打包后的文件提供传统浏览器兼容性支持

xiaoxian521 3 years ago
parent
commit
eb0771e7ec
6 changed files with 301 additions and 452 deletions
  1. 3 0
      .env.production
  2. 2 1
      build/index.ts
  3. 1 0
      package.json
  4. 284 450
      pnpm-lock.yaml
  5. 1 0
      types/global.d.ts
  6. 10 1
      vite.config.ts

+ 3 - 0
.env.production

@@ -6,3 +6,6 @@ VITE_ROUTER_HISTORY = "hash"
 
 # 线上环境后端地址
 VITE_PROXY_DOMAIN_REAL = ""
+
+# 是否为打包后的文件提供传统浏览器兼容性支持 支持 true 不支持 false
+VITE_LEGACY = false

+ 2 - 1
build/index.ts

@@ -6,7 +6,8 @@ const warpperEnv = (envConf: Recordable): ViteEnv => {
     VITE_PUBLIC_PATH: "",
     VITE_PROXY_DOMAIN: "",
     VITE_PROXY_DOMAIN_REAL: "",
-    VITE_ROUTER_HISTORY: ""
+    VITE_ROUTER_HISTORY: "",
+    VITE_LEGACY: false
   };
 
   for (const envName of Object.keys(envConf)) {

+ 1 - 0
package.json

@@ -85,6 +85,7 @@
     "@types/qs": "^6.9.7",
     "@typescript-eslint/eslint-plugin": "4.31.0",
     "@typescript-eslint/parser": "4.31.0",
+    "@vitejs/plugin-legacy": "^1.6.4",
     "@vitejs/plugin-vue": "^1.10.2",
     "@vitejs/plugin-vue-jsx": "^1.3.1",
     "@vue/compiler-sfc": "^3.2.24",

File diff suppressed because it is too large
+ 284 - 450
pnpm-lock.yaml


+ 1 - 0
types/global.d.ts

@@ -69,6 +69,7 @@ declare global {
     VITE_PROXY_DOMAIN: string;
     VITE_PROXY_DOMAIN_REAL: string;
     VITE_ROUTER_HISTORY: string;
+    VITE_LEGACY: boolean;
   }
 
   declare interface ServerConfigs {

+ 10 - 1
vite.config.ts

@@ -1,6 +1,7 @@
 import { resolve } from "path";
 import vue from "@vitejs/plugin-vue";
 import svgLoader from "vite-svg-loader";
+import legacy from "@vitejs/plugin-legacy";
 import vueJsx from "@vitejs/plugin-vue-jsx";
 import { warpperEnv, regExps } from "./build";
 import { viteMockServe } from "vite-plugin-mock";
@@ -28,6 +29,7 @@ const alias: Record<string, string> = {
 export default ({ command, mode }: ConfigEnv): UserConfigExport => {
   const {
     VITE_PORT,
+    VITE_LEGACY,
     VITE_PUBLIC_PATH,
     VITE_PROXY_DOMAIN,
     VITE_PROXY_DOMAIN_REAL
@@ -162,7 +164,14 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
           setupProdMockServer();
         `,
         logger: true
-      })
+      }),
+      // 是否为打包后的文件提供传统浏览器兼容性支持
+      VITE_LEGACY
+        ? legacy({
+            targets: ["ie >= 11"],
+            additionalLegacyPolyfills: ["regenerator-runtime/runtime"]
+          })
+        : null
     ],
     optimizeDeps: {
       include: [

Some files were not shown because too many files changed in this diff