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

使用unplugin-vue-components会导致externalGlobal失效 #152

Closed
yzqdev opened this issue May 3, 2024 · 4 comments
Closed

使用unplugin-vue-components会导致externalGlobal失效 #152

yzqdev opened this issue May 3, 2024 · 4 comments

Comments

@yzqdev
Copy link

yzqdev commented May 3, 2024

使用unplugin-vue-components会导致externalGlobal失效

复现仓库 https://github.com/yzqbugs/monkey-bug

具体操作

我的vite配置 https://github.com/yzqbugs/monkey-bug/blob/main/vite.config.ts
不使用

import { ElMessageBox ,ElButton,ElDialog} from 'element-plus'

导入(见App.vue)

pnpm build则会生成一个不带ElementPlus的monkey-bug.user.js,大小为202.07 kB,并且,这个use.js内部会添加ElMessageBox ,ElButton,ElDialog的代码,即elemen-plus没有使用cdn

如下面的图片,打包出来,没有element-plus的exportVarName(ElementPlus)

如何使external生效?

此时,把App.vue里面的

//import { ElMessageBox ,ElButton,ElDialog} from 'element-plus'

注释去掉,重新打包,体积为3.39 kB

搜了unplugin-vue-components的issue,貌似不是unplugin-vue-components的原因

https://github.com/unplugin/unplugin-vue-components/issues?q=external

@lisonge
Copy link
Owner

lisonge commented May 25, 2024

  1. update vite-plugin-monkey version to 4.0.0-alpha.1 in package.json
  2. update field element-plus to element-plus/es in vite.config.ts
- "element-plus": cdn.npmmirror(
+ "element-plus/es": cdn.npmmirror(

@lisonge
Copy link
Owner

lisonge commented May 29, 2024

Is this problem solved?

@yzqdev
Copy link
Author

yzqdev commented May 29, 2024

Now it works well, thank you!

  1. update vite-plugin-monkey version to 4.0.0-alpha.1 in package.json
  2. update field element-plus to element-plus/es in vite.config.ts
- "element-plus": cdn.npmmirror(
+ "element-plus/es": cdn.npmmirror(

@yzqdev yzqdev closed this as completed May 29, 2024
@lisonge
Copy link
Owner

lisonge commented May 29, 2024

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

2 participants