# Consume Kotlin Multiplatform Library in vanilla JS web app

**URL:** <https://discuss.kotlinlang.org/t/consume-kotlin-multiplatform-library-in-vanilla-js-web-app/22152>\
**Category:** Multiplatform\
**Created:** [June 18, 2021, 4:22am UTC](https://discuss.kotlinlang.org/t/consume-kotlin-multiplatform-library-in-vanilla-js-web-app/22152 "2021-06-18T04:22:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![richiksc](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@richiksc](https://discuss.kotlinlang.org/u/richiksc)\
**Post date:** [June 18, 2021, 4:22am UTC](https://discuss.kotlinlang.org/t/consume-kotlin-multiplatform-library-in-vanilla-js-web-app/22152/1 "2021-06-18T04:22:45Z")

</div>

I have a Kotlin multiplatform library that targets Kotlin/JVM and Kotlin/JS (Browser) containing some domain classes and business logic that needs to be shared across both frontend and backend. Consuming the multiplatform library as a simple Gradle/Maven dependency in the Java-based backend project was relatively easy and flawless. However, I’d like to write the frontend in plain Javascript or Typescript (not Kotlin) but call methods and classes in the Kotlin multiplatform library (which I have built for JS as well). Is this possible, and how would I do it?

---

<div class="post-metadata">

**Author:** ![david.g](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@david.g](https://discuss.kotlinlang.org/u/david.g)\
**Post date:** [October 7, 2021, 12:58am UTC](https://discuss.kotlinlang.org/t/consume-kotlin-multiplatform-library-in-vanilla-js-web-app/22152/2 "2021-10-07T00:58:53Z")

</div>

I followed this steps:

- run jsBrowserDevelopmentWebpack (there is another one for production)
- copy/paste the .js in your web app
- add it to an HTML using 
- use classes and functions with their whole package, something like  
 → \< module \>.\< your \>.\< package \>.\< class name \>  
(if you are working on a multiplatform project maybe you need to add the project name and a ‘-’)  
 → \< project name \>-\< module \>.\< your \>.\< package \>.\< class name \>

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [October 7, 2021, 6:26am UTC](https://discuss.kotlinlang.org/t/consume-kotlin-multiplatform-library-in-vanilla-js-web-app/22152/3 "2021-10-07T06:26:09Z")

</div>

Actually, this recipe is for the legacy compilator. IR compilator has a grade flag called `binaries.library()` which generates a bundle alongside ts typings, that could be consumed by external webpack. Or you can use [GitHub - mpetuska/npm-publish: Gradle plugin for NPM package publishing. Allows for arbitrary publishing as well as seamless integration with Kotlin JS/MPP plugins.](https://github.com/mpetuska/npm-publish) to produce an npm library bundle.
