Vue 3/Vite中如何在scoped style标签中Glob导入CSS文件?
解决Vue组件scoped样式中Glob导入依赖模块CSS的问题
问题场景
需要在Vue组件的scoped <style>标签中,通过Glob语法从依赖模块导入CSS文件,概念代码如下:
<!-- myComponent.vue --> <style scoped lang="less"> #myId { /* 默认情况下@import不支持Glob语法 */ @import (less) 'foo_module/src/**/*.css'; } </style> <template>...</template> <script>...</script>
尝试过两种方案但未成功:
- 使用
postcss-import-ext-glob插件,在vite.config.js中配置后,在组件中用@import-glob无效。 - 使用
import.meta.glob获取到了CSS字符串,但无法注入到scoped<style>中(模板插值在
相关产品推荐
相关产品推荐

