Kaynağa Gözat

加固乾坤打包配置,解决打包后白屏的问题

ZGC4846 5 gün önce
ebeveyn
işleme
e80304b1f2
1 değiştirilmiş dosya ile 19 ekleme ve 22 silme
  1. 19 22
      vue.config.js

+ 19 - 22
vue.config.js

@@ -26,7 +26,7 @@ const sassOptions = {
 module.exports = {
   publicPath,
   lintOnSave: false,
-  outputDir: 'dist',
+  outputDir: "dist",
   productionSourceMap: false,
   configureWebpack: {
     performance: {
@@ -34,13 +34,12 @@ module.exports = {
       maxEntrypointSize: 2000000,
     },
     output: {
-      // 把子应用打包成 umd 库格式
-      library: {
-        type: "umd",
-        name: `${name}`,
-      },
-
+      // qiankun 子应用:打包成 umd,并避免全局对象在严格模式下异常
+      library: `${name}-[name]`,
+      libraryTarget: "umd",
       chunkLoadingGlobal: `webpackJsonp_${name}`,
+      globalObject: "window",
+      uniqueName: name,
     },
     // Vue2 + vue-style-loader:样式靠副作用注入,不导出 default;
     // Webpack5 会对 `import style0 from ...` 报 missing export,可安全忽略
@@ -62,7 +61,13 @@ module.exports = {
         name: "redirect-to-app",
         middleware(req, res, next) {
           const url = (req.url || "").split("?")[0];
-          if (url === "/" || url === "/hr" || url === "/hr/" || url === "/hr-pc" || url === "/hr-pc/") {
+          if (
+            url === "/" ||
+            url === "/hr" ||
+            url === "/hr/" ||
+            url === "/hr-pc" ||
+            url === "/hr-pc/"
+          ) {
             res.redirect(publicPath);
             return;
           }
@@ -93,7 +98,7 @@ module.exports = {
         // target: 'http://aiot.zoomwin.com.cn:51001/api',
         // target: 'http://f222326r53.imwork.net',
         // target: 'http://aiot.zoomwin.com.cn:51005/api',
-        target: 'http://192.168.1.147:18086',
+        target: "http://192.168.1.147:18086",
         changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
         pathRewrite: {
           "^/api": "",
@@ -113,19 +118,11 @@ module.exports = {
   },
   chainWebpack(config) {
     config.plugins.delete("prefetch");
-    // set svg-sprite-loader
-    // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
-    // config.module
-    //   .rule('icons')
-    //   .test(/\.svg$/)
-    //   .include.add(resolve('./src/icons'))
-    //   .end()
-    //   .use('svg-sprite-loader')
-    //   .loader('svg-sprite-loader')
-    //   .options({
-    //     symbolId: 'icon-[name]'
-    //   })
-    //   .end();
+    // qiankun:入口 js 需落在 body,避免 head+defer 导致生命周期读取失败
+    config.plugin("html").tap((args) => {
+      args[0].inject = "body";
+      return args;
+    });
     config.module.rule("svg").exclude.add(resolve("src/icons")).end();
     config.module
       .rule("icons")