W
Wasp•11mo ago
RichardHpa

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 manageable
24 Replies
Vinny (@Wasp)
Vinny (@Wasp)•11mo ago
YES this is coming in a future update but isn't possible at the moment 😦
matijash
matijash•11mo ago
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 🙂
RichardHpa
RichardHpaOP•11mo ago
amazing that great to hear, just doing some testing with opensaas is already making these files quite bloated
MEE6
MEE6•11mo ago
Wohooo @RichardHpa, you just became a Waspeteer level 1!
fooosieee
fooosieee•2mo ago
any update on this?
Filip
Filip•2mo ago
Not yet unfortunately. Are you using main.wasp.ts or main.wasp?
martinsos
martinsos•2mo ago
We are quite close though
fooosieee
fooosieee•2mo ago
ts
Filip
Filip•2mo ago
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
fooosieee
fooosieee•2mo ago
nah with ts amazing can split it amazingly
Filip
Filip•2mo ago
You mean it works already?
fooosieee
fooosieee•2mo ago
Wasp TypeScript config (*.wasp.ts) | Wasp
This document assumes your app works with Wasp >= 0.15.
martinsos
martinsos•2mo ago
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?
mm
mm•5d ago
@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 instance
DEV Community
Splitting Wasp TS Config?
Splitting Wasp TS Config, Can we do it? Overview The early support for TS...
martinsos
martinsos•5d ago
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 :).
mm
mm•5d ago
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
mm
mm•5d ago
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
No description
genyus
genyus•3d ago
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:
[ Wasp ] ext-src/config/apis.wasp.ts(1,10): error TS2305: Module '"wasp-config"' has no exported member 'ApiConfig'.
[ Wasp ] ext-src/config/apis.wasp.ts(1,21): error TS2305: Module '"wasp-config"' has no exported member 'App'.
[ Wasp ] ext-src/config/core.wasp.ts(2,3): error TS2305: Module '"wasp-config"' has no exported member 'App'.
[ Wasp ] ext-src/config/core.wasp.ts(3,3): error TS2305: Module '"wasp-config"' has no exported member 'AuthConfig'.
[ Wasp ] ext-src/config/core.wasp.ts(4,3): error TS2305: Module '"wasp-config"' has no exported member 'ClientConfig'.
[ Wasp ] ext-src/config/core.wasp.ts(5,3): error TS2305: Module '"wasp-config"' has no exported member 'DbConfig'.
[ Wasp ] ext-src/config/core.wasp.ts(6,3): error TS2305: Module '"wasp-config"' has no exported member 'EmailSenderConfig'.
<snip>
[ Wasp ] ext-src/config/apis.wasp.ts(1,10): error TS2305: Module '"wasp-config"' has no exported member 'ApiConfig'.
[ Wasp ] ext-src/config/apis.wasp.ts(1,21): error TS2305: Module '"wasp-config"' has no exported member 'App'.
[ Wasp ] ext-src/config/core.wasp.ts(2,3): error TS2305: Module '"wasp-config"' has no exported member 'App'.
[ Wasp ] ext-src/config/core.wasp.ts(3,3): error TS2305: Module '"wasp-config"' has no exported member 'AuthConfig'.
[ Wasp ] ext-src/config/core.wasp.ts(4,3): error TS2305: Module '"wasp-config"' has no exported member 'ClientConfig'.
[ Wasp ] ext-src/config/core.wasp.ts(5,3): error TS2305: Module '"wasp-config"' has no exported member 'DbConfig'.
[ Wasp ] ext-src/config/core.wasp.ts(6,3): error TS2305: Module '"wasp-config"' has no exported member 'EmailSenderConfig'.
<snip>
I've been fiddling for a while, but haven't yet found a way to avoid these errors
miho
miho•3d ago
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-config
Wasp TypeScript config (*.wasp.ts) | Wasp
This document assumes your app works with Wasp >= 0.15.
mm
mm•3d ago
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
genyus
genyus•3d ago
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:
"devDependencies": {
"wasp-config": "file:../../../../.local/share/wasp-lang/0.15.2/data/packages/wasp-config"
}
"devDependencies": {
"wasp-config": "file:../../../../.local/share/wasp-lang/0.15.2/data/packages/wasp-config"
}
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:
#!/usr/bin/env node
export {};
//# sourceMappingURL=run.d.ts.map
#!/usr/bin/env node
export {};
//# sourceMappingURL=run.d.ts.map
I have no idea how or why this discrepancy is occurring.
miho
miho•3d ago
@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 verdict
genyus
genyus•3d ago
Actually, 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!

Did you find this page helpful?