I have added the JS target for our Kotlin Multi platform project. The project is named STT.
JavaScript
x
12
12
1
js(IR) {
2
binaries.executable()
3
browser {
4
commonWebpackConfig {
5
cssSupport.enabled = true
6
}
7
webpackTask {
8
output.libraryTarget = "umd"
9
}
10
}
11
}
12
When I look at the build folder or when I run the JS task jsRun
the JS lib looks empty.
Here is for example the stt.js
from the build folder
JavaScript
1
14
14
1
(function (root, factory) {
2
if (typeof define === 'function' && define.amd)
3
define(['exports'], factory);
4
else if (typeof exports === 'object')
5
factory(module.exports);
6
else
7
root.stt = factory(typeof sttalg === 'undefined' ? {} : stt);
8
}(this, function (_) {
9
'use strict';
10
return _;
11
}));
12
13
14
That essentially is an empty object
However, when I use the BOTH or Legacy that file looks ok
JavaScript
1
12
12
1
js(LEGACY) {
2
binaries.executable()
3
browser {
4
commonWebpackConfig {
5
cssSupport.enabled = true
6
}
7
webpackTask {
8
output.libraryTarget = "umd"
9
}
10
}
11
}
12
What am I missing ?
Advertisement
Answer
The IR backend doesn’t export any code to js by default. You need to add @JsExport
to the declarations you want accessible. See https://kotlinlang.org/docs/js-to-kotlin-interop.html#jsexport-annotation