https://kotlinlang.org logo
#javascript
Title
# javascript
e

Edoardo Luppi

03/25/2024, 3:12 PM
When targeting
browser
and
binaries.library()
the Webpack task is not executed, is it expected?
a

Artem Kobzar

03/25/2024, 3:30 PM
I feel, that in this case we generate only klib, so, there is no JS to process it with the Webpack
e

Edoardo Luppi

03/25/2024, 3:31 PM
Mmh, you can run
jsBrowserProductionLibraryDistribution
, so there is some JS output
a

Artem Kobzar

03/25/2024, 3:32 PM
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

Edoardo Luppi

03/25/2024, 3:34 PM
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

Ilya Goncharov [JB]

03/26/2024, 10:02 AM
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

Edoardo Luppi

03/26/2024, 10:03 AM
@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

Ilya Goncharov [JB]

03/26/2024, 10:11 AM
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

Edoardo Luppi

03/26/2024, 10:14 AM
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

Ilya Goncharov [JB]

03/26/2024, 10:15 AM
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

Edoardo Luppi

03/26/2024, 10:18 AM
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