Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/host/app/app.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script setup lang="ts">
import HostCard from "./components/HostCard.vue";
import HostSsrComponent from "./components/HostSsrComponent.vue";

const message = "Hello World";
</script>

<template>
Expand All @@ -11,13 +13,15 @@ import HostSsrComponent from "./components/HostSsrComponent.vue";
<div class="component-grid">
<HostSsrComponent />
<Suspense>
<RemoteWidget />
<RemoteWidget :message />
<template #fallback>
<div>Loading remote widget...</div>
</template>
</Suspense>
<Suspense>
<RemoteCounter />
<RemoteCounter>
<template #footer> Slot from host </template>
</RemoteCounter>
<template #fallback>
<div>Loading remote counter...</div>
</template>
Expand Down
2 changes: 1 addition & 1 deletion apps/remote/app/app.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<template>
<Widget />
<Widget message="Remote Hello" />
</template>
5 changes: 5 additions & 0 deletions apps/remote/app/components/exposed/Counter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
const count = ref(0);
const hydrated = ref(false);

const slots = defineSlots<{
footer(): any;
}>();

onMounted(() => {
hydrated.value = true;
});
Expand Down Expand Up @@ -48,6 +52,7 @@ onMounted(() => {
>
Remote counter: {{ count }}
</button>
<slot name="footer"> Default footer </slot>
<span
:style="{
alignItems: 'center',
Expand Down
7 changes: 7 additions & 0 deletions apps/remote/app/components/exposed/Widget.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<script setup lang="ts">
interface Props {
message: string;
}

defineProps<Props>();

const count = ref(0);
const hydrated = ref(false);

Expand All @@ -22,6 +28,7 @@ onMounted(() => {
"
data-e2e="APP__CARD"
>
<h1>Message: {{ message }}</h1>
<div class="icon">
<svg
enable-background="new 0 0 512 512"
Expand Down
34 changes: 11 additions & 23 deletions packages/nuxt/src/remotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,30 +211,18 @@ export function registerRemoteComponents(
addTypeTemplate({
filename: "types/module-federation-components.d.ts",
getContents() {
return `
import type { Component } from "vue";

${components
.map(
(component) => `
declare module ${JSON.stringify(component.importPath)} {
const component: Component;
export default component;
}
`,
)
.join("\n")}

declare module "vue" {
export interface GlobalComponents {
${components
.map((component) => `${component.componentName}: Component;`)
.join("\n")}
}
}
return `declare module "vue" {
export interface GlobalComponents {
${components
.map(
(component) =>
`${component.componentName}: typeof import("../../../${component.remoteName}/.nuxt/components.d.ts")["${component.exposedName}"];`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vvnsrzn for your help.
This path only works for sibling monorepo folders.
Let's instead use the module-federation/vite dts prop.

)
.join("\n\t\t")}
}
}

export {};
`;
export { };`;
},
});
}
Expand Down
Loading