What target should I use if I want to compile kotlin.js into a single service worker js file using the latest kotlin gradle plugin? Targeting browser produces a single .js file that has a reference to a window object, but the service worker file cannot contain a window object.
Grantas33
03/05/2020, 11:00 PM
targeting common.js and using the compileKotlinJs task produces a single .js file that requires a "kotlin" module (require("kotlin"), I'm not sure how to include the kotlin module into the same .js file
i
Ilya Goncharov [JB]
03/06/2020, 8:24 AM
If you use target
browser()
it build bundle with all dependencies included in
build/distributions
By default it produces
umd
format
For worker you may need something else, maybe webpack default
So you can override it with
Copy code
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target
kotlin {
target {
browser {
webpackTask {
output.libraryTarget = Target.VAR
output.library = "something" // while you define var name of js it should be valid js name, which you project name may not satisfy
}
}
}
}
g
Grantas33
03/06/2020, 9:23 PM
Thanks a lot. Library target Target.SELF did the trick. When using Target.VAR I was encountering a duplicate target file error when running build task