Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow auto-importing of pages/*.imba #9

Open
andregoldstein opened this issue Sep 16, 2022 · 2 comments
Open

Allow auto-importing of pages/*.imba #9

andregoldstein opened this issue Sep 16, 2022 · 2 comments

Comments

@andregoldstein
Copy link

I'm wondering if it would be possible to use Vite's glob imports to auto import the relevant pages/*.imba file as documented in the Svelte example? Eg:

const pages = import.meta.glob('../pages/**/*.svelte')

createInertiaApp({ 
  resolve: name => pages[`../pages/${name}.svelte`](),
  setup({ el, App, props }) {
    new App({ target: el, props })
  },
})

This would save having to manually import each imba page file. Not sure if it's possible using the current way createInertiaApp resolves...

If not, it's not a huge deal to create a pages/index.imba file and to import each page there and then include it in the entry file bit might be one less step!

@andregoldstein
Copy link
Author

andregoldstein commented Sep 17, 2022

Taking a look at Vite docs, it's possible to use glob imports with the eager setting set to true, this will fully import the global tags (in my case loading layouts and pages)

import.meta.glob(['../layouts/**/*.imba', '../pages/**/*.imba'], { eager: true })

EDIT

Although this obviously loads all the pages initially as opposed to lazily from within the resolve method

@haikyuu
Copy link
Owner

haikyuu commented Sep 20, 2022

This would work @andregoldstein Give it a try. I'm working on stabilizing the vite plugin and experience in Imba. I'll polish this library afterwards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants