update structure

This commit is contained in:
antony 2024-12-21 18:50:22 +07:00
parent a809901535
commit 955dd07c7f
15 changed files with 119 additions and 55 deletions

View File

@ -1,23 +0,0 @@
<template>
<div class="container mx-auto p-4">
<h1 class="text-2xl font-bold mb-4">Nuxt 3 MFE Host App</h1>
<div class="grid grid-cols-1 gap-4">
<HostComponent />
<Suspense>
<template #default>
<RemoteComponent />
</template>
<template #fallback>
<div>Loading remote component...</div>
</template>
</Suspense>
</div>
</div>
</template>
<script setup>
import { defineAsyncComponent } from 'vue'
import HostComponent from './components/HostComponent.vue'
const RemoteComponent = defineAsyncComponent(() => import('remote/RemoteComponent'))
</script>

17
host/layouts/default.vue Normal file
View File

@ -0,0 +1,17 @@
<template>
<div>
<div class="layout">
<NuxtLink to="/">Home</NuxtLink>
<NuxtLink to="/contact">Contact</NuxtLink>
<NuxtLink to="/contact/properties">Contact Properties</NuxtLink>
</div>
<slot />
<div>--HOST Footer--</div>
</div>
</template>
<style scoped>
.layout {
display: flex;
gap: 20px;
}
</style>

View File

@ -10,6 +10,7 @@
"preview": "nuxt preview", "preview": "nuxt preview",
"postinstall": "nuxt prepare", "postinstall": "nuxt prepare",
"clean": "rimraf .output", "clean": "rimraf .output",
"clean2": "rimraf --glob node_modules",
"serve": "serve .output/public -p 3000" "serve": "serve .output/public -p 3000"
}, },
"dependencies": { "dependencies": {

View File

@ -0,0 +1,27 @@
<template>
<div class="container mx-auto p-4">
<h1 class="text-2xl font-bold mb-4">Contact page (Host)</h1>
<div class="grid grid-cols-1 gap-4">
<div class="rmt">
<Suspense>
<template #default>
<RemoteContactRouter />
</template>
<template #fallback>
<div>Loading remote component...</div>
</template>
</Suspense>
</div>
</div>
</div>
</template>
<script setup>
import { defineAsyncComponent } from "vue"
const RemoteContactRouter = defineAsyncComponent(() =>
import("remote/ContactRouter")
)
</script>
<style scoped></style>

3
host/pages/index.vue Normal file
View File

@ -0,0 +1,3 @@
<template>
<div>Index page</div>
</template>

View File

@ -1,6 +0,0 @@
<template>
<div class="container mx-auto p-4">
<h1 class="text-2xl font-bold mb-4">Nuxt 3 MFE Remote App</h1>
<RemoteComponent />
</div>
</template>

View File

@ -0,0 +1,27 @@
<template>
<div>
<component v-if="asyncPageComponent" :is="asyncPageComponent" />
</div>
</template>
<script setup>
import { defineAsyncComponent } from "vue"
/**
* @todo
* it'll be nice if there is a way to dynamically match route and render..
*/
console.log(">>", window.location.pathname)
const Index = defineAsyncComponent(() => import("@/pages/contact/index.vue"))
const Properties = defineAsyncComponent(() =>
import("@/pages/contact/properties.vue")
)
let asyncPageComponent
if (/\/contact\/properties/.test(window.location.pathname)) {
asyncPageComponent = Properties
} else {
asyncPageComponent = Index
}
</script>

View File

@ -1,22 +0,0 @@
<template>
<div class="p-4 border rounded bg-blue-50 sty1">
<h2 class="text-xl mb-2">Remote Component</h2>
<p>This component is exposed from the remote application</p>
</div>
</template>
<script setup>
defineComponent({
name: 'RemoteComponent'
})
onMounted(() => {
console.log('mounted')
})
</script>
<style>
.sty1 {
background: pink;
}
</style>

View File

@ -0,0 +1,6 @@
<template>
<div>
Remote layout
<slot />
</div>
</template>

View File

@ -11,7 +11,7 @@ export default defineNuxtConfig({
name: "remote-app", name: "remote-app",
filename: "remoteEntry.js", filename: "remoteEntry.js",
exposes: { exposes: {
"./RemoteComponent": "./components/RemoteComponent.vue" "./ContactRouter": "./components/ContactRouter.vue"
}, },
shared: [] shared: []
// shared: ['vue'] // shared: ['vue']

View File

@ -10,7 +10,7 @@
"preview": "nuxt preview", "preview": "nuxt preview",
"postinstall": "nuxt prepare", "postinstall": "nuxt prepare",
"clean": "rimraf .output", "clean": "rimraf .output",
"serve": "serve .output/public -p 3001" "serve": "serve .output/public -p 3001 --cors"
}, },
"dependencies": { "dependencies": {
"nuxt": "^3.13.0", "nuxt": "^3.13.0",

1
remote/pages/about.vue Normal file
View File

@ -0,0 +1 @@
<template><div>about rmt</div></template>

View File

@ -0,0 +1,12 @@
<template>
<div class="rmt">
<h1>rmt/pages/contact/index.vue</h1>
<div>Contact index</div>
</div>
</template>
<script setup></script>
<style scoped>
.rmt {
background-color: antiquewhite;
}
</style>

View File

@ -0,0 +1,11 @@
<template>
<div>
<h1>rmt/pages/contact/properties.vue</h1>
<div>Contact prop</div>
</div>
</template>
<script setup>
definePageMeta({
name: "contact1"
})
</script>

10
remote/pages/index.vue Normal file
View File

@ -0,0 +1,10 @@
<script setup lang="ts">
// import ContactRouter from "~/components/ContactRouter.vue"
</script>
<template>
<div class="container mx-auto p-4">
<h1 class="text-2xl font-bold mb-4">Nuxt 3 MFE Remote App</h1>
<!-- <ContactRouter /> -->
</div>
</template>