https://kotlinlang.org logo
#kobweb
Title
# kobweb
c

Chi-Hsuan Wu

03/28/2023, 4:00 AM
Hi, can I use Kobweb in an existing Kotlin multiplatform project?
d

David Herman

03/28/2023, 4:01 AM
It depends what you're trying to do.
Basically, you have to think of Compose for Web DOM as a fairly different UI approach. It will be hard to share UI code between C4W DOM and, say, Android and Desktop.
However, if you just want to share business logic between a C4W site and your other projects, then sure, that's fine.
In short Compose for Web DOM is getting to use Kotlin instead of JS/TS Compose for Web Canvas is getting to use Kotlin instead of Dart (i.e. Flutter)
c

Chi-Hsuan Wu

03/28/2023, 4:07 AM
I am currently using Compose DOM to let my existing KMM project support for web. My problem is that I cannot find a way to set up Kobweb without creating a new project.
d

David Herman

03/28/2023, 4:07 AM
You basically need to consider on of your modules is now a Kobweb application module
To do that, you need to do a few things...
1. Set a dependency on my artifact repository location 2. Apply the Kobweb Gradle Application plugin 3. Update your build.gradle.kts script 4. Add a .kobweb/conf.yaml file in your Kobweb application module's folder
The dependency on the artifact repository location can be found in settings.gradle.kts
If I were you, I'd create a new empty module in your application, maybe
site
or whatever, and then create a dummy project on the side, and copy it over.
(Note that the Kobweb Gradle Application plugin is pretty opinionated. It wants to create your index.html and main.kt files for you, and you probably already have one, which is why it's probably good to create a new module)
Once you have the new module building within your project, copy code over incrementally.
I apologize there's not a better way yet. With my limited resources, I still need to focus on supporting new projects, but I hope this will get better someday. I can help you out if you are willing to try!
c

Chi-Hsuan Wu

03/28/2023, 4:13 AM
Thanks, I'll give it a try
d

David Herman

03/28/2023, 4:13 AM
You may want to play with a dummy Kobweb project first to make sure you are happy with what Kobweb does for you.
Good luck!
c

Chi-Hsuan Wu

03/28/2023, 7:55 AM
It works! Thanks!
d

David Herman

03/28/2023, 8:17 PM
Wow, great job!!
I'm impressed you navigated that on your own 👍 Sorry if it was frustrating.
In case anyone finds this thread in some future search, I went ahead and added a section to the README with more detailed instructions: https://github.com/varabyte/kobweb#adding-kobweb-to-an-existing-project
228 Views