Import kotlin.js file using @JsModule annotation

I would like to know if it is possible to import kotlin.js file, using @JsModule annotation.
The problem is that I need just one output js script. Now I’m merging the scripts together using gradle.

Sorry, I am not sure I understand your problem correctly. @JsModule generates require calls (for CommonJS) so that your code plays together with module systems. For bundling the output together Kotlin/JS relies on existing JavaScript tools.

Webpack is a popular one. Kotlinx.coroutines library example uses it to bundle together two libraries, a module output, and a CSS file.

If your case is simpler, consider kotlin-frontend-plugin. It still uses webpack internally, but requires minimal configuration and produces a JS file with kotlin.js and your code bundled together.

If you are using react.js, you should probably use it’s native optimizer

In some cases you can just glue JS files together in the correct order (moduleKind plain and UMD), but you’ll have to do that manually still (e.g. use gradle).

1 Like

Thank you, now I understand