File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,6 +28,41 @@ plugins {
2828
2929## Lazy functions
3030
31+ Puts a function in a separate JS chunk. The chunk will be loaded when the function is called the first time.
32+
33+ #### Setup
34+
35+ Add the dependency ` kotlin-js ` of [ Kotlin Wrappers] ( https://github.com/JetBrains/kotlin-wrappers ) to your project.
36+
37+ ``` kotlin
38+ // root settings.gradle.kts
39+ dependencyResolutionManagement {
40+ repositories {
41+ mavenCentral()
42+ }
43+
44+ versionCatalogs {
45+ create(" kotlinWrappers" ) {
46+ val wrappersVersion = " 2025.6.0"
47+ from(" org.jetbrains.kotlin-wrappers:kotlin-wrappers-catalog:$wrappersVersion " )
48+ }
49+ }
50+ }
51+ ```
52+
53+ ``` kotlin
54+ // build.gradle.kts
55+ sourceSets {
56+ jsMain {
57+ dependencies {
58+ implementation(kotlinWrappers.js)
59+ }
60+ }
61+ }
62+ ```
63+
64+ #### Usage
65+
3166``` kotlin
3267// App.kt
3368suspend fun main () {
@@ -43,9 +78,11 @@ suspend fun main() {
4378}
4479
4580// createCalculationWithHeavyLibrary.kt
81+ import js.lazy.Lazy
82+ import js.lazy.LazyFunction
83+
4684/* *
47- * - Function will be located in separate JS chunk
48- * - Chunk will be loaded when function will be called first time
85+ * Function will be located in separate JS chunk
4986 */
5087@Lazy
5188val createCalculationWithHeavyLibrary = LazyFunction <Int > {
You can’t perform that action at this time.
0 commit comments