#Laravel Starter Kit, app.ts - store .vue pages in different directories
1 messages · Page 1 of 1 (latest)
I got it working with a second folder
but it gave a small error in the console
there must be a way
why restrict a project to one folder?
resolvePageComponent() accepts an Array
I mean, it’s possible if you write your own resolve method instead of using the one from Laravel
I couldnt find the source for resolvePageComponent()
just lead me to a typescript definition file
Thats for fallback pages, while it might work with some adjustments, its not really the intended use-case I think, as you’d still have issues if you have the same paths
You could just move the starter files to a folder like pages/starter/?
I may have to do this
what's "fallback pages"?
If the path can’t be found in the directory it would take the second one as the view. So like you try to render a view that doesn’t exist, instead of throwing an error, it would render your fallback view, such as an error page
so my pages aren't even being loaded by resolvePageComponent()
they are being loaded magically from laravel-vite plugin?
It might with a dynamic one, but not sure about that fallback thing. From the pr the usecase is just a single error page if the page can’t be found
Hmm it seems it also works with a variable path, but then you still can’t have duplicate pathnames
And your glob import would need to contain files in both of those paths
resolvePageComponent -> accepts array where the 2nd value is the fail case, I see what you mean
thats what I did at first, and it worked (with a console error)
but I tried to add a 3rd location and it broke
😆
I’ve seen some online that just wrote their own render method (you don’t need to use the resolvePageComponent from Laravel), basically with an “if starts with ‘web/‘ look here, else look there”
But imho, in this case I might argue it makes things more messy than it solves 😅
Something akin to this https://github.com/inertiajs/inertia/issues/188#issuecomment-675091658
its a bit dated, since the method is now just resolve, but that’s kind of the general idea
where can I find out what
resolve: (name) =>
resolvePageComponent(`./pages/${name}.vue`,
import.meta.glob<DefineComponent>('./pages/**/*.vue')),
is actually doing?
do you know where the source is?
I could do something like your github link
I may just stick my whole project into ./pages though, a bit of a fail, but if it can't be helped
https://github.com/laravel/vite-plugin/blob/2.x/src/inertia-helpers/index.ts
it doesn’t do much haha
when I click around in the editor it never takes me to the source
wow man its only a few lines of code
shouldn't be too hard to remake
#💬-general message
This might give you an idea of what you could do, but in my opinion you should just go with what Robert said and separate the pages in subdirectories
why did you make it async?
Just noticed that I left it async when I modified my production snippet, in my case I also had a default layout
your solution seems safe
it's just a bit messy
do you forsee any future problems with it_
cause I would like to keep my app very separate from the starter kit files
Ehh it’s a workaround for managing a huge monorepo, personally I wouldn’t do something like that
For a single non-monorepo application*
If I may ask, why’d you want to keep them separate from the starter kit files? Because that’s kinda how the starter kits are set up; it’s a starting point for you to continue from, so it’s kinda encouraged to also modify those files to your liking, they’re part of your app, not separate files that don’t belong to your app
the starter kit is mostly login stuff
which I won't touch
theres many composables, ui files, etc, that are separate from my logic
Then you can just keep them as-is right? They’re already located in the auth part of your pages
is there a performance problem if I put my whole app in ./pages/app ?
look at js/components folder, its full of so much stuff
cant put my app in there
https://inertiajs.com/docs/v2/advanced/code-splitting#code-splitting
If by performance problem you mean “large js file” then not necessarily, that default resolver does per-page code splitting for you
I don’t really understand, those files are not pages, you can relocate them if you like. The idea behind the starter kit is also that you’d use those components in your own pages, since that would unify the styling of your app. So you have pages, which decide the layout of every page. And you’d have components, which are reusable small pieces you use across multiple pages
yep that's true
but I just think the other files are distracting
look at layouts, theres 3 folders in there
I was thinking if maybe import.meta.glob<DefineComponent> took time to parse more files
That happens build-time, so the user wouldn’t notice
Just trying to think along; if you wouldn’t use a starter kit, how would you structure it? So where would you place the auth views, where would you place the layouts etc. Maybe you can restructure the app to your liking that way?
I’m probably wrong, but it kinda sounds like you’re hiding the starter kit files because the structure isn’t how you’d put it, so introducing workarounds to hide that, which might become more messy as the project grows
I meant, fully ignoring the starter kit 😅 like if you’d built it from scratch
probably the same as the starter kit
it's a great starter kit
no doubt
but I can't use it's folders without getting distracted
composables like 'useInitials.ts'
haha man
resolve: (name) => {
console.log(name)
if (name.startsWith('myapp')){
return resolvePageComponent(...)
}
}
I hacked it up like this
and it works
but this console.log is getting called twice
and even though it loads the page
it still prints an error in the console
// resources/views/app.blade.php
@vite(
[
'resources/js/app.ts',
"resources/js/pages/{$page['component']}.vue"
]
)