onebay / vite-plugin-imp

A vite plugin for import library component style automatic.
MIT License
232 stars 24 forks source link

当按需引入的组件依赖其他组件时,依赖的组件css未导入 #8

Closed Mrchangchang closed 3 years ago

Mrchangchang commented 3 years ago

引入的组件依赖其他基础组件时,未导入依赖度基础组件的css

psaren commented 3 years ago

请提供相关代码以复现

Mrchangchang commented 3 years ago

使用Field 组件,依赖cell组件css未导入

<template>
  <h1>{{ msg }}</h1>

  <div>
    <button @click="count++">count is: {{ count }}</button>
  </div>
  <Button>Vant Button</Button>
  <Progress :percentage="3" />
  <Field placeholder="请输入"></Field>
  <ElButton>element-plus button</ElButton>
</template>

<script lang="ts">
import { ref, defineComponent } from 'vue'
import { Button, Progress, Field } from 'vant'
import { ElButton } from 'element-plus'
export default defineComponent({
  name: 'HelloWorld',
  components: {
    Button,
    Progress,
    ElButton,
    Field
  },
  props: {
    msg: {
      type: String,
      required: true
    }
  },
  setup: () => {
    const count = ref(0)
    return { count }
  }
})
</script>

<style scoped>
a {
  color: #42b983;
}
</style>

image

psaren commented 3 years ago

应该按下面配置

// vite.config.ts
{
  optimizeDeps: {
    entries: 'vant/es/**/*.js'
  },
   plugins:[  
    vitePluginImp({
      libList: [
        {
          libName: 'vant',
          style(name) {
            return `vant/es/${name}/style/index.js`
          }
        }]
      })
    ]
  },
}
Mrchangchang commented 3 years ago

谢谢,问题已经解决。