originjs / vite-plugin-federation

Module Federation for vite & rollup
Other
2.36k stars 240 forks source link

提交个bug #211

Open uwenking opened 2 years ago

uwenking commented 2 years ago

parsedOptions.prodShared.forEach((value) => { const shareName = value[0]; // pick every shared moduleId const usedSharedModuleIds = new Set(); const sharedModuleIds = new Map(); // exclude itself parsedOptions.prodShared .filter((item) => item[0] !== shareName) .forEach((item) => { //It is necessary to judge whether item[1].id is null, otherwise always get through the endless loop in bundle if(item[1].id) sharedModuleIds.set(item[1].id, item[0]) }); depInShared.set(shareName, usedSharedModuleIds); const deps = new Set(); findDependencies.apply(that, [ value[1].id, deps, sharedModuleIds, usedSharedModuleIds ]); value[1].dependencies = deps; });

this code here shoule be

uwenking commented 2 years ago

[originjs:federation] Maximum call stack size exceeded error during build: RangeError: Maximum call stack size exceeded at addDep (D:\Code\kmap\node_modules.pnpm\@originjs+vite-plugin-federation@1.1.6\node_modules\@originjs\vite-plugin-federation\dist\index.js:2036:25)

flyfishzy commented 2 years ago

Please provide a reproduction project.

lazyTai commented 1 year ago

this is my vite.config.js

import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue2";
import federation from "@originjs/vite-plugin-federation";
import topLevelAwait from "vite-plugin-top-level-await";
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const PROCESS_CONSTAINT = loadEnv(mode, process.cwd());
  const VITE_PUBLIC_PATH = PROCESS_CONSTAINT.VITE_BASE_PREFIX;
  return {
    base: VITE_PUBLIC_PATH || "/",
    resolve: {
      alias: {
        "@": "/src",
      },
    },
    plugins: [
      vue(),
      federation({
        name: "app1",
        remotes: {
          app2: "/federation/lianban2/assets/lianban2-legacy.js",
        },
      }),
      topLevelAwait({
        promiseExportName: "__tla",
        promiseImportName: (i) => `__tla_${i}`,
      }),
    ],
    server: {
      host: "",
      force: true,
      port: 89,
      proxy: {
        // 选项写法
        "/api": {
          target: "http://apidev.szqerp.com/", // 代理的目标地址
          // target: 'http://api.szqerp.com/', // 代理的目标地址
          changeOrigin: true, // 开发模式,默认的origin是真实的 origin:lo
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
        "/federation/lianban2": {
          target: "http://localhost:8080/", // 代理的目标地址
          changeOrigin: true, // 开发模式,默认的origin是真实的 origin:lo
          rewrite: (path) => path.replace("/federation/lianban2", ""),
        },
      },
    },
    build: {
      target: "esnext",
      minify: false,
      cssCodeSplit: true,
      rollupOptions: {
        // input: {
        //  ""
        // },
        output: {
          manualChunks(id) {
            // console.log('manualChunks id', id);
            if (id.includes("/vue@")) {
              return "vue";
            } else if (id.includes("/vue-router")) {
              return "VueRouter";
            } else if (id.includes("element-ui/lib/")) {
              return "chunk-element-ui";
            } else if (id.includes("@base/svg-icon")) {
              return "lib_svgIcon";
            } else if (id.includes("node_modules")) {
              // console.log(id.toString().split("node_modules/")[1].split("/"))
              // console.log(id.toString().split("node_modules/")[1].split("/")[1].toString())
              return id
                .toString()
                .split("node_modules/")[1]
                .split("/")[1]
                .toString();
            }
          },
        },
      },
    },
  };
});

package.json

 "@originjs/vite-plugin-federation": "^1.2.3",
    "vite-plugin-top-level-await": "^1.3.1",
    "@types/moment": "^2.13.0",
    "@vitejs/plugin-vue2": "^1.1.2",
    "axios": "^0.21.1",
    "cross-env": "^7.0.3",
    "dayjs": "^1.11.3",
    "dingtalk-jsapi": "^2.14.2",
    "element-ui": "^2.15.9",
    "js-cookie": "^3.0.1",
    "koa": "^2.13.4",
    "koa-router": "^12.0.0",
    "lib-flexible": "^0.3.2",
    "lodash": "^4.17.21",
    "lodash-es": "^4.17.21",
    "moment": "^2.29.4",
    "nprogress": "^0.2.0",
    "reset.css": "^2.0.2",
    "rollup-plugin-external-globals": "^0.8.0",
    "short-uuid": "^4.2.2",
    "simplebar": "^5.3.8",
    "simplebar-vue": "^1.6.9",
    "sortablejs": "^1.15.0",
    "unplugin-vue-define-options": "^0.6.1",
    "uuid": "^8.3.2",
    "vant": "^3.4.3",
    "vite-plugin-chunk-split": "^0.2.7",
    "vite-plugin-imp": "^2.2.0",
    "vite-plugin-svg-icons": "^2.0.1",
    "vue": "^2.7.0",
    "vue-router": "3.4.9"