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

microapp引入requirejs报错 #1192

Open
VVzhouxiaobai opened this issue Apr 30, 2024 · 2 comments
Open

microapp引入requirejs报错 #1192

VVzhouxiaobai opened this issue Apr 30, 2024 · 2 comments
Labels
feature Planned functions sandbox sandbox TODO

Comments

@VVzhouxiaobai
Copy link

问题描述

vite子应用在index.html里面引入requirejs,单独运行子应用没有问题,把子应用引入到主应用就报define is not define

复现步骤

1.在子引用中,引入microapp

<script src="https://requirejs.org/docs/release/2.3.6/comments/require.js?id=2"></script> <title>Vite App</title> 2.在main.js中通过define引入远程组件的vue和elementPlus define("vue", [], function () { return Vue; }); define("element-plus", [], function () { return ElementPlus; }); const NODE_ENV = import.meta.env.MODE; window.process = { env: { NODE_ENV } }; 然后单独运行子应用没有问题,但是引入到主应用后就会报define is not define
@bailicangdu bailicangdu added feature Planned functions common common question TODO sandbox sandbox and removed common common question labels Apr 30, 2024
@bailicangdu
Copy link
Member

在微前端中通过var定义的顶层变量无法泄漏为全局变量
image

@bailicangdu
Copy link
Member

这里给出一种临时的解决方案:1、将js下载到本地引入 2、将var改为window定义
image

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

No branches or pull requests

2 participants