Skip to content

Commit

Permalink
perf: dont use eager imports for loading pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Mar 2, 2024
1 parent 9ad1fea commit a32f139
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 7 additions & 2 deletions resources/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import { vTooltip } from 'floating-vue'
import { createInertiaApp } from '@inertiajs/vue3'
import { createApp, h, ref, type DefineComponent } from 'vue'
import { autoAnimatePlugin } from '@formkit/auto-animate/vue'
import { resolvePageComponent } from '@adonisjs/inertia/helpers'

console.log('app.ts')

void createInertiaApp({
progress: { color: '#5468FF' },

resolve: (name) => {
const pages = import.meta.glob<DefineComponent>('./pages/**/*.vue', { eager: true })
return pages[`./pages/${name}.vue`] as any
return resolvePageComponent(
`./pages/${name}.vue`,
import.meta.glob<DefineComponent>('./pages/**/*.vue'),
)
},

setup({ el, App, props, plugin }) {
Expand Down
12 changes: 8 additions & 4 deletions resources/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { VTooltip } from 'floating-vue'
import { vTooltip } from 'floating-vue'
import { createInertiaApp } from '@inertiajs/vue3'
import { renderToString } from '@vue/server-renderer'
import { createSSRApp, h, type DefineComponent, ref } from 'vue'
import { resolvePageComponent } from '@adonisjs/inertia/helpers'

export default function render(page) {
return createInertiaApp({
page,
render: renderToString,
resolve: (name) => {
const pages = import.meta.glob<DefineComponent>('./pages/**/*.vue', { eager: true })
return pages[`./pages/${name}.vue`]
return resolvePageComponent(
`./pages/${name}.vue`,
import.meta.glob<DefineComponent>('./pages/**/*.vue'),
)
},

setup({ App, props, plugin }) {
const app = createSSRApp({ render: () => h(App, props) })
.use(plugin)
.directive('tooltip', VTooltip)
.directive('tooltip', vTooltip)
.directive('autoAnimate', {})

app.config.globalProperties.modelViewerScriptLoaded = ref(false)

Expand Down
2 changes: 1 addition & 1 deletion resources/views/app_root.edge
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">

@vite(['resources/app.ts'])
@vite(['resources/app.ts', `resources/pages/${page.component}.vue`])
</head>

<body>
Expand Down

0 comments on commit a32f139

Please sign in to comment.