Wasm
Compose can be compiled to WebAssembly (Wasm) for use in modern browsers.
Introduction
With Kotlin, you have the power to build applications and reuse mobile and desktop user interfaces (UIs) in your web projects through Compose and Wasm.
For web platforms, Compose Multiplatform uses Kotlin/Wasm as its compilation target. Applications built with Kotlin/Wasm and Compose Multiplatform use a wasm-js target and run in browsers.
Explore this online demo of an application built with Compose Multiplatform and Kotlin/Wasm
Additionally, you can use the most popular Kotlin libraries in Kotlin/Wasm out of the box. Like in other Kotlin and Multiplatform projects, you can include dependency declarations in the build script.
Get started
Create a new project with the Web target and the Share UI.
Once the project loads, select composeApp [wasmJs] in the list of run configurations and click Run.
The web application opens automatically in your browser. Alternatively, you can open the following URL in your browser when the run is finished:
http://localhost:8080/
The port number can vary because the 8080 port may be unavailable. You can find the actual port number in the output of the Gradle build.
Gradle
You can run the wasmJsBrowserDevelopmentRun task to compile the project and open the HTML file in the browser.
.\gradlew wasmJsBrowserDevelopmentRunIf you prefer, you can use the --continuous flag to keep the browser open and automatically reload the page when you modify the code.
.\gradlew wasmJsBrowserDevelopmentRun --continuousGenerate artifacts
Generate your project’s artifacts to publish on a website:
./gradlew wasmJsBrowserDistributionEstás leyendo una vista previa.
Inicia sesión para leer el artículo completo. Cualquier cuenta abre 4 artículos gratuitos al mes; el alumnado y el profesorado leen las páginas de su curso sin límite.
Iniciar sesión