unplugin / unplugin-auto-import

Auto import APIs on-demand for Vite, Webpack and Rollup
MIT License
3.08k stars 192 forks source link

在 vuepress2 中无法生效 #409

Closed WangJincheng4869 closed 11 months ago

WangJincheng4869 commented 11 months ago

Clear and concise description of the problem

目前不知道是因为 vuepress2 不支持还是这个插件不支持,所以到这里来提问。

Suggested solution

我想了解一下这个插件的工作原理,我的docs和我的主工程是在一起的。通过此插件配置配置,当我想在 docs 里演示组件时会提示通过自动导入的工具类不存在。看有没有什么方案可以解决这个问题。

Alternative

No response

Additional context

No response

Validations

lishaobos commented 11 months ago

需要一个可复现的 git 仓库

WangJincheng4869 commented 11 months ago

已经使用 resolve 解决

AutoImport({
  imports: ['vue'],
  dirs: [resolve(__dirname, '../../src/util/**'), resolve(__dirname, '../../src/hooks/**')],
  dts: resolve(__dirname, '../../typings/auto-imports.d.ts'),
  resolvers: [
    ElementPlusResolver({
      // 我们的样式已经进行了全量导入,这里不需要再导入。为什么选择了全量导入?答:因为按需导入会有大量重复的 css 变量,与减小包大小是相悖的,反而全量引入 css 会更好。
      importStyle: false,
    }),
  ],
}),