I'm confused by node.js with KotlinJS or Kotlin mu...
# javascript
g
I'm confused by node.js with KotlinJS or Kotlin multiplatform. I don't know tons about node but it seems like a simulator for a browser (maybe server too) and a generic package manager? I don't understand when to use it, I thought I had read that node modules (like metro 4, bootstrap, three.js, fs, etc) shouldn't be served up to the client/frontend, is that true? I'm confused by what implementation(npm()) is really doing. I sort of imagined that node npm would manage all my packages and other node packages like webpack would export/minify/obfuscate everything for me in a configurable way. I'm not sure.
j
From what I understood,
implementation(npm("..."))
on gradle simply adds these dependencies to the generated
package.json
for your project. As part of the Gradle build,
npm
is used behind the scenes with this generated
package.json
to actually fetch the dependencies, and webpack is used to build your project and generate a single .js file.
g
That's pretty much what I was expecting except that webpack doesn't seem to fetch the dependacies I declare even though Node downloaded them, I think its an error in the multiplatform webpack thingy... the automatically generated webpack.config is looking in the wrong spot and what gets generated in that file doesn't seem to be configurable from gradle.
i
Can you attach a link to your project?
g
Sure I'll send it thru private chat, need to figure out how to bring node into this project and stop using the resources folder for storing the js libraries and the build/distributions folder for serving them up. That's the intent behind nodejs/require.js right, would you say this is the right goal? Could you eliminate Node entirely from the multipplatform build and use require.js instead? Which is the right way? Still trying to figure out node. I have 2 multiplatform formal projects ATM that are quite different and I haven't solved this problem on either... I see I think you work for jetBrains... can the docs be updated as part of this support 😃? Sent.
i
g
Thanks. But my main question, should I even be trying to include js dependcies using the resources folder or should I be using node for that? you can do a implementation(npm("three"))... I don't really know what that is doing but I think its downloading the original source code for it to node_modules. Can't figure out how to use them though.
i
You should use
npm()
for this. Resource folder is a workaround.
g
Okay cool, I thought so but wasn't sure... still learning this...