Hi! How do I generate an executable file from JS? ...
# eap
l
Hi! How do I generate an executable file from JS? I have
Copy code
kotlin {
    js(IR) {
        nodejs()
        binaries.executable()
    }
}
as my setup, and when running
build
it outputs a JS file to
build/js/packages/...
, but files from
resources
are nowhere to be found over there. What's the proper way to generate a executable file that works on its own?
t
If you need independent
js
dist for now: 1. Use
browser()
instead of
node()
2. Use
build/distributions/
as dist source
l
By doing that I'm not able to execute it in a NodeJS environment, right?
đŸš« 1
There's no way to generate a runnable node file?
On M1 there's this:
Please note that since this is only a preview, they are not added to the
distributions
folder by default for now
How to add it manually then?
t
Gradle copy task 🙂
l
Ah, I see... I thought there would be a solution out of the box 😂
Thanks, @turansky !
t
In
M3
resources copied automatically
From
src/main/resources
Try run
./gradlew clean
before to refresh Kotlin/JS settings
cc @Ilya Goncharov [JB]
l
I'm using M3 tho... I'll create an example project
Executing
gradlew build
won't carry the file in resources to the package directory
t
Check please
build/distributions
dir of subproject
l
I know browser works, but I need it for node. I'm not using Kotlin JS in a browser
t
For now
node
is just limited
browser
l
ty
browser
uses
window
, which is not defined in a node environment
It's not possible to use
i
Yes, for now
nodejs
doesn’t have its own bundle task, if you need some resources you can manually copy it If you use
browser
there is way to make it possible to run in Node.JS environment, you need change configuration for webpack in
webpack.config.d
. You need to create this folder in your project and create any
js
file with content
Copy code
config.output = config.output || {}
config.output.globalObject = “this”
It will be fixed in 1.4.20 (https://youtrack.jetbrains.com/issue/KT-40159)
👍 2