Can I split up the main.wasp file into seperate files
Hey Everyone. I am really enjoying learning wasp and can easily see myself using this alot to make some of my web apps. I am just wondering is there anyway to split out the code in the
main.wasp
file into seperate files as I could easily see this file getting quite large and out of hand. What i mean is there a way to have a seperate file for all the routes (and maybe even break that until into sub routes), queries, jobs, actions, DB schemas.
If not that would be a great thing for a future version of wasp to be able to do, would help with making the code abit more readable and manageable24 Replies
YES this is coming in a future update but isn't possible at the moment 😦
100% agree! As @Vinny (@Wasp) mentioned, this is one of the features we'll be tackling next.
It sounds straightforward, but it also opens the questions of (sub)modules, imports etc, so that's why we want to take enough time to refine this. Recent changes of v0.12 put the foundations for all this in place 🙂
amazing that great to hear, just doing some testing with opensaas is already making these files quite bloated
Wohooo @RichardHpa, you just became a Waspeteer level 1!
any update on this?
Not yet unfortunately. Are you using
main.wasp.ts
or main.wasp
?We are quite close though
ts
Yeah, that should be coming soon.
If it's a major issue for you, I could figure out how to hack it together right now, but I recommend sticking to a single file if not too big of a deal
nah with ts
amazing
can split it amazingly
You mean it works already?
Wasp TypeScript config (*.wasp.ts) | Wasp
This document assumes your app works with Wasp >= 0.15.
Right, you are using Wasp TS config, but did you managed to split it into multiple files? If so, can you maybe share a bit of details how that went, any issues, or was it just simple?
@RichardHpa @martinsos I recently decided to switch to the
.ts
version. and also searched for a solution. Then I came up with this: https://dev.to/medardm/splitting-wasp-ts-config-2iei Please let me know if it's not going to affect anything. Would be great also if you can expose a type for the App instanceDEV Community
Splitting Wasp TS Config?
Splitting Wasp TS Config, Can we do it? Overview The early support for TS...
Oh interesting somebody showed on Medium how they split Wasp TS config into multiple fiels! I will summon @Filip , who wrote Wasp TS Config and will answer this the best :).
interesting. can you also send me the medium article? thanks!
Hi about what I said about exposing the App type, it's just in wasp-config lol my bad
`import { App } from "wasp-config" I will update the article. We can properly split the config in this case
I just updated the article you can check this section. or just check this gist https://gist.github.com/medardm/263b2c933186eb1a496fa743c756edc7
Gist
Wasp-lang: An example of splitting/organizing main wasp file (OpenS...
Wasp-lang: An example of splitting/organizing main wasp file (OpenSaaS) into different sections - actions.wasp.ts
Did you have to make any changes outside of the *.wasp.ts files? I attempted this refactor operation in my project following your example and while all the code looks correct, I get errors during compilation:
I've been fiddling for a while, but haven't yet found a way to avoid these errors
Could you retry setting up the
wasp-config
lib with wasp ts-setup
? Maybe just go through the steps and see if something is off: https://wasp-lang.dev/docs/general/wasp-ts-configWasp TypeScript config (*.wasp.ts) | Wasp
This document assumes your app works with Wasp >= 0.15.
I started with making it work first using the main.wasp.ts. before I started splitting the code but up to you. you should start with the link @miho sent
I did follow these steps initially and got the main.wasp.ts file working fine. The problem I described only started when I tried to refactor it, following the example in @mm's Gist
wasp ts-setup
added the following entry to my package.json:
When I examine the output files in my .wasp folder, I see that for .wasp/main.wasp.ts and the linked .wasp.ts files in .wasp/config, wasp-config
resolves to /Users/gary/.local/share/wasp-lang/0.15.2/data/packages/wasp-config/dist/index
and they're all happy
However, for the .wasp.ts files in .wasp/out/sdk/wasp/ext-src/config with the reported errors, wasp-config
resolves to /Users/gary/.local/share/wasp-lang/0.15.2/data/packages/wasp-config/dist/run
And checking of the contents of the run.d.ts file:
I have no idea how or why this discrepancy is occurring.@sodic will have to jump in to sort this out, but I think the trouble here is that we don't really support splitting up
main.wasp.ts
into multiple files. But I'll let Filip look at this and make the final verdictActually, explaining the problem gave me a clue to what the cause was. I'd placed the new sub-files under /src/config, and realised they were getting compiled in the wrong location. I moved them outside of the src folder to /config and it all works!