# Different ways to distribute and integrate Kotlin/JS library

DevFeed: [Different ways to distribute and integrate Kotlin/JS library](<https://devfeed.tech/articles/different-ways-to-distribute-and-integrate-kotlin-js-library-24710.md>)

Original publisher: [Read original article](<https://dev.to/touchlab/different-ways-to-distribute-and-integrate-kotlinjs-library-1hg3>)

Author: Jigar Brahmbhatt

Published: 2022-07-11T20:24:11Z

Content type: tutorial

Language: en

Sources: [Touchlab](<https://devfeed.tech/sources/touchlab.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>), [Gradle](<https://devfeed.tech/topics/gradle.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [Webpack](<https://devfeed.tech/topics/webpack.md>), [npm](<https://devfeed.tech/topics/npm.md>), [TypeScript](<https://devfeed.tech/topics/typescript.md>), [browser](<https://devfeed.tech/topics/browser.md>)

Tags: [browser](<https://devfeed.tech/tags/browser.md>), [coding](<https://devfeed.tech/tags/coding.md>), [community](<https://devfeed.tech/tags/community.md>), [development](<https://devfeed.tech/tags/development.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [inclusive](<https://devfeed.tech/tags/inclusive.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlinjs](<https://devfeed.tech/tags/kotlinjs.md>), [kotlinmultiplatform](<https://devfeed.tech/tags/kotlinmultiplatform.md>), [library](<https://devfeed.tech/tags/library.md>), [npm](<https://devfeed.tech/tags/npm.md>), [software](<https://devfeed.tech/tags/software.md>), [typescript](<https://devfeed.tech/tags/typescript.md>), [webpack](<https://devfeed.tech/tags/webpack.md>)

## AI overview

A tutorial on distributing and integrating Kotlin/JS libraries in a Kotlin Multiplatform setup. It explains browser and Node.js targets, library and executable binaries, Gradle distribution tasks, Webpack bundles, and publishing output as an npm module with JavaScript and TypeScript usage.

## Source excerpt

Note that examples in this post use Kotlin 1.7.0 In the previous post in the Kotlin/JS series, we learned about @JsExport to expose Kotlin code on the JS side. Now, we would look at various ways to distribute a JS library code through a KMP setup. Table Of Contents Gradle Setup Webpack Node Module npm-publish Using the library Use webpack executable HTML JavaScript TypeScript Use as node module HTML JavaScript TypeScript Gradle Setup If you don't already have a JS target in your KMP library project, then you should check out this blog post first. Let's look at common options to use for JS target, js(IR) { browser() nodejs() binaries.library() binaries.executable() } browser() It sets the JavaScript target execution environment as browser. It provides a Gradle task--jsBrowserTest that runs all js tests inside the browser using karma and webpack. nodejs() It sets the JavaScript target execution environment as nodejs. It provides a Gradle task--jsNodeTest that runs all js tests inside nodejs using the built-in test framework. binaries.library() It tells the Kotlin compiler to produce Kotlin/JS code as a distributable node library. Depending on which target you've used along with this, you would get Gradle tasks to generate library distribution files. Kotlin browser tasks -------------------- jsBrowserDevelopmentLibraryDistribution jsBrowserDevelopmentLibraryPrepare jsBrowserProductionLibraryDistribution jsBrowserProductionLibraryPrepare Kotlin node tasks ----------------- jsNodeDevelopmentLibraryDistribution jsNodeDevelopmentLibraryPrepare jsNodeDevelopmentRun jsNodeProductionLibraryDistribution jsNodeProductionLibraryPrepare jsNodeProductionRun jsNodeRun EitherjsBrowserProductionLibraryDistribution or jsNodeProductionLibraryDistribution task generates output files in <YourLibModule>/build/productionLibrary folder binaries.executable() It tells the Kotlin compiler to produce Kotlin/JS code as webpack executable .js files. Enabling this option generates the following Grad