-
Notifications
You must be signed in to change notification settings - Fork 6
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
[求助]element-plus的CSS如何CDN加载? #30
Comments
关于加入css的功能的话这个插件和 |
我目前查看了他的文档。检查你的本地项目是否包含 具体配置如下 cdn({
modules: ['vue', {name:'ElementPlus',aliases:['es'],spare:['https://cdn.jsdelivr.net/npm/element-plus@2.4.2/dist/index.min.css'], {name:'vue-router',aliases:['auto','auto/routes']}}
}) |
这个log 应该是我无心之举。后面版本会进行修复 |
我应该是看错了。ElementPlus 这个应该没有用你自己配置的element-plus 是正确的。只需要把spare 移进去。 |
你可以使用 [
{ name: 'vue', relativeModule: './dist/vue.global.prod.js' },
{
name: 'element-plus',
aliases: ['es', 'lib'],
relativeModule: './dist/index.full.min.js',
spare: ['https://cdn.jsdelivr.net/npm/element-plus@2.4.2/dist/index.min.css']
},
{ name: 'vue-demi', relativeModule: './dist/index.iife.js' },
{ name: 'vue-router', aliases: ['auto', 'auto/routes'], relativeModule: './dist/vue-router.global.prod.js' },
{ name: 'pinia', relativeModule: './dist/iife.prod.js' }
] |
具体使用了哪些插件呢。能提供一份配置表吗 |
当然可以,package.json
vite.config.ts:
|
@toimc 我在本地制作了一个最小复现demo。我觉得你并不需要isProd 这个字段。 |
我做了一个最小 demo,https://github.com/toimc/vite-vue-cdn-demo ,你可以在你本地试一下,pnpm dev正常,pnpm build-only && pnpm preview,无法运行。 关于: 我觉得你并不需要isProd 这个字段,autoImport 和components的resolvers照常使用即可——说明一下我这么做的原因: 理由一:由于项目中使用到component动态组件,有一些场景下,需要动态从服务端传递过来一些可能在当前resolver下没有打包进来了element-plus中的组件,所以要这么干; 理由二:由于"这2个插件会附带引入css 打包进chunk",正如你所说,我发现这2个插件会导致css会有100kb的增加,非常不nice,我直接考虑全部cdn加载,避免重复打包。 关于router的这个我没遇到问题——我上面已经回复,我目前的解决方案,可以参看最小 demo中的vite配置。 非常感谢!!! |
关于router的这个问题。 我暂时没什么好思路。这个包不会特别大我会找个时间研究下这个插件具体的工作流。目前你可以先把他移除。以及 |
Pinia和VueDemi 配置错了应该是 |
看起来是插件的bug。我会进行一个修复。 应急措施的话就得看文档了。 |
你是指vite-plugin-cdn插件有问题,还是指AutoImport及Components这两个插件有问题? 冒昧问一下,有什么思路没有?卡在这里了,想压缩项目打包的体积。 尝试一:rollup插件方式External + html静态资源导入又与vite-plugin-pwa这个插件冲突,打包之后html中无js,css |
|
因为目前这类的插件实现原理都是大同小异无非是看谁的external做的更好罢了。 |
我发布了 |
经过我的尝试,已经OK了,感谢开源作者无私的付出。
最终配置,提供给有缘人。 |
感谢作者的无私付出,有两个小疑问。
[1] 我想在项目中,让element-plus的css能够像在https://www.npmjs.com/package/vite-plugin-cdn-import 这个库中一样cdn加载,如何实现?
[2] 这个库 https://github.com/posva/unplugin-vue-router ,不知道作者清楚不?文件自动路由,但是配合当前vite-plugin-cdn2,即使设置了'vue-router' cdn加载,依旧在打包之后,会把vue-router打包进项目。
@nonzzz
The text was updated successfully, but these errors were encountered: