我目前在从我的组件库包中导出自定义 Vue 组件时遇到问题。
假设ComponentLib
具有以下文件夹结构,其中调用了我要导出的自定义组件icon.vue
|-src
|-components
|-icon.vue
|-index.ts
|-package.json...and other config files
ComponetLib/src/components/icon.vue
<template functional>
...
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';
import { IconModel } from '../index';
@Component({})
export default class IconComponent extends Vue {
@Prop()
icon!: IconModel;
}
</script>
ComponentLib/src/index.ts
export type IconModel = {
id: string;
content: string;
}
export { default as Icon } from 'components/icon.vue';
构建后,在此dist
文件夹中,我可以看到正在导出的以下类型。
|-dist
|-...
|-types
|-components
|-icon.vue.d.ts
|-index.d.ts
|-package.json
dist/types/index.d.ts
export declare type IconModel = {
id: string;
content: string;
};
export { default as Icon } from 'components/icon.vue';
这是结构MainProject
|-src
|-components
|-profile.vue --> imports @ComponentLib/components/icon.vue
|-index.ts
|-package.json...and other config files
profile.vue
通过导入自定义icon.vue
组件
import Icon from '@ComponentLib/types/components/icon.vue';
但是当我编译时,我收到一条错误消息module not found
,它无法解析这个引用。
但是当我将相同的组件放在MainProject/src/components
文件夹中时,编译器似乎很高兴。我突然想到出口可能有问题。但我不确定我错过或做错了哪一部分。