This project demonstrates how to export Kotlin code as native TypeScript modules using JetBrains' Kotlin Multiplatform.
The sample consists of three modules: :shared, :module-a, and :module-b, showcasing how to configure the export via annotations.
JsExport Export is an experimental feature and subject to change in any future releases.
:shared- The main shared module that aggregates and exports the other modules (:module-aand:module-b) as native TypeScript modules.:module-a- A sample Kotlin module to be exported asModuleAin TypeScript.:module-b- Another sample Kotlin module to be exported asModuleBin TypeScript.
- Clone this repository.
- Open the project in your favorite IDE/editor.
- Run
./gradlew shared:jsBrowserProductionLibraryDistributionin the terminal. - Install dependencies using
npm installin the repository root. - Run the webApp using
npm start --workspace=webAppor run tests withnpm test --workspace=webAppin the repository root.
- outputModuleName: Allows setting a custom module name for the exported Kotlin module.
- packageJson: Allows setting a custom property for the
package.json, so that we set upkmp-libname for the exported Kotlin library. - kotlin.js.ir.output.granularity: Allows compiling the Kotlin code per-file, which is natural for JavaScript.
- For more information on Kotlin Multiplatform, check out the Kotlin Multiplatform Documentation.