Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importmap 在子应用沙箱环境中不生效 #1543

Open
ollieLiu1988 opened this issue Mar 5, 2025 · 0 comments
Open

importmap 在子应用沙箱环境中不生效 #1543

ollieLiu1988 opened this issue Mar 5, 2025 · 0 comments

Comments

@ollieLiu1988
Copy link

importmap 在子应用沙箱环境中不生效

项目demo地址

demo地址

base-module-federation 是基座,子应用是 sub-module-federation,基座和子应用都用 vite 打包配置如下:

忽略 vue,和 vue-router 采用 cdn 映射到全局

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { createHtmlPlugin } from "vite-plugin-html";
export default defineConfig({
  plugins: [
    vue(),
    createHtmlPlugin({
      minify: false,
      inject: {
        data: {
          injectScript: `
           <script type="importmap">
            {
              "imports": {
                "vue": "https://aplus-front-cdn.oss-cn-hangzhou.aliyuncs.com/aplus-frontend-static-resource/vue.esm-browser.prod.js",
                "vue-router": "https://aplus-front-cdn.oss-cn-hangzhou.aliyuncs.com/aplus-frontend-static-resource/vue-router.esm-browser.js",
                "@vue/devtools-api": "https://unpkg.com/@vue/[email protected]/lib/esm/index.js"
              }
            }
          </script>
          `,
        },
      },
    }),
  ],
  server: {
    headers: {
      "Access-Control-Allow-Origin": "*",
    },
  },
  build: {
    rollupOptions: {
      external: ["vue", "vue-router"],
      output: {
        format: "es",
        paths: {
          vue: "https://aplus-front-cdn.oss-cn-hangzhou.aliyuncs.com/aplus-frontend-static-resource/vue.esm-browser.prod.js",
          "vue-router":
            "https://aplus-front-cdn.oss-cn-hangzhou.aliyuncs.com/aplus-frontend-static-resource/vue-router.esm-browser.js",
        },
      },
    },
  },
});

子应用可以独立运行

子应用可以独立运行

微前端环境下子应用失效

貌似 importmap 在子应用沙箱环境中不生效
importmap 在子应用沙箱环境中不生效
importmap 在子应用沙箱环境中不生效

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant