1

If I have two different kotlin js modules in project can I create two different output js file for each of them? If yes, how to configure it?

  jsMain {
            dependencies {
                implementation npm ("text-encoding", "0.7.0")
                implementation npm ("bufferutil", "4.0.1")
                implementation npm ("utf-8-validate", "5.0.2")
                implementation npm ("abort-controller", "3.0.0")
                implementation npm ("fs", "0.0.1-security")
                implementation kotlin('stdlib-js')
                implementation "io.ktor:ktor-client-json-js:$ktor_version"
                implementation "io.ktor:ktor-client-js:$ktor_version"
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.8"
                implementation "io.ktor:ktor-client-serialization-js:$ktor_version"
                implementation "pl.treksoft:kvision:$kvisionVersion"
                implementation "pl.treksoft:kvision-i18n:$kvisionVersion"
            }
        }
     jsSecure {
            dependencies {
                implementation npm ("text-encoding", "0.7.0")
                implementation npm ("bufferutil", "4.0.1")
                implementation npm ("utf-8-validate", "5.0.2")
                implementation npm ("abort-controller", "3.0.0")
                implementation npm ("fs", "0.0.1-security")
                implementation kotlin('stdlib-js')
                implementation "io.ktor:ktor-client-json-js:$ktor_version"
                implementation "io.ktor:ktor-client-js:$ktor_version"
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.8"
                implementation "io.ktor:ktor-client-serialization-js:$ktor_version"
                implementation "pl.treksoft:kvision:$kvisionVersion"
                implementation "pl.treksoft:kvision-i18n:$kvisionVersion"
            }
        }

1 Answer 1

3

Firstly, you can create separate Gradle module for this case. It will be the best way, because it is not internal API, and you can define dependency relation between modules. So just create new Gradle module and configure it as usual. It provides full experience as a separate output file including separate output file (https://kotlinlang.org/docs/reference/js-project-setup.html)

Using internal API, you can work inside one Gradle module but several JS targets. It is very similar on creating separate module. It provides separate output file for compilation also. For example

kotlin {
   js {
     // ...
   }
   js("secure") {
      // ...
   }
}

And finally, you can create separate compilation inside one module and one Kotlin/JS target. But this API is not stable

kotlin {
  js {
    // ...
    val secure = compilations.create("secure")
    secure.source(sourceSets["jsMain"]
  }
}

For example this API does not provide Webpack and other integration stuff for your custom compilation. But it provides separate output file of compilation.

So I recommend to create new Gradle module, because it is more robust. If there is any reason why this way does not work for you, please tell.

Sign up to request clarification or add additional context in comments.

1 Comment

Do you still recommend the multi-module approach or have there been new updates?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.