When targeting `browser` and `binaries.library()` ...
# javascript
e
When targeting
browser
and
binaries.library()
the Webpack task is not executed, is it expected?
a
I feel, that in this case we generate only klib, so, there is no JS to process it with the Webpack
e
Mmh, you can run
jsBrowserProductionLibraryDistribution
, so there is some JS output
a
Oh, so, in this case it's better to ask @Ilya Goncharov [JB]. Ilya what do we expect from the
binaries.library()
as an output?
gratitude thank you 1
e
To clarify also for @Ilya Goncharov [JB], this is related to the previous post. Customizing the Webpack configuration might help me solve that issue.
Looked up the code and I can see
Copy code
compilation.binaries
    .matching { it is Executable }
in
KotlinBrowserJsIr.configureBuild
, so to some degree it looks like it's done on purpose
i
Key idea in
binaries.library
to not prepare final bundle, but provide JavaScript library as set of files, webpack is expected to be executed on final phase in final application
e
@Ilya Goncharov [JB] thanks Ilya, that makes sense. Related to the post above then, the right point where to modify the Webpack configuration is in the app that will bundle the Kotlin library.
Related to Webpack support, I have seen others create custom
KotlinWebpack
tasks. Is that supposed to be possible, or is it just a hack?
i
Yes, I think, the best place to configure webpack is in the final app project But if you really need webpack for your library, it is better to use
binaries.executable
As for custom
KotlinWebpack
task. Gradle is designed as system where there are many things are possible, so you can't forbidden create custom tasks of specific type. It is not designed by us for such purpose and we are not ready to deeply support such cases, but it is nature of Gradle, so I could not name it a hack, so users could create such tasks at their own risk
e
binaries.executable
looks like the better approach to avoid too many customizations. As far as I understand tho,
executable
doesn't output a
package.json
, so using it for a library is by default not possible. Or did I not configure it correctly?
i
Yes, that's true. But there is a task named
publicPackageJson
which can produce it 🙂 But yes, for executable public package json was not supposed to be, because it is just working application
e
Thanks! Somehow we should put all those info into a K/JS "recipes" document. I think other people will, or did have in the past, the same doubts. Haven't found any resource that groups everything together yet.
👍 1