I have a Kotlin/JS application that I have configu...
# javascript
d
I have a Kotlin/JS application that I have configured to output a binary.executable. I want to then use that binary as a library in a Javascript project in Idea. How would I go about doing so?
I guess this might be more of a Gradle question than a Kotlin question.
b
You don't. Use binaries.library() for that
Here's sample setup in case you haven't seen it yet. https://github.com/mpetuska/npm-publish/tree/master/sandbox/ts-consumer
d
I'm confused. This is a typescript application, no?
b
The extra plugin there is optional if you'd prefer to collect required files yourself instead
Ts is just a superset of js. Both use the same set of libraries
d
I understand that. I have a Kotlin/JS application that I want to "package".
b
And that's exactly what the link above does
d
At the moment, using this approach, I see the package created in a build directory:
Copy code
js(IR) {
        moduleName = "kool-core"
        binaries.executable()
        compilations["main"].packageJson {
            customField("name", "kool-core")
        }
        browser { }
    }
The issue is that in a completely different project I want to use the package created here.
Do I publish it to Maven local?
Can I publish it to npm local?
Then in the other project how do I include it? Do I somehow copy it from dependencies to a local folder? Do I just use package.json if I'm publishing to a local npm?
b
Just browse what the link above does. It solves your use-case exactly.
d
Ok.
Allow me another question, is there a way to do this without publishing to registry.npmjs.org ? I'm in the development cycle and would rather no publish this globally.
b
Yes, ts-consumer does that too
Works fully offline
d
How would I configure the npmPublish registries section?
b
You don't since you don't publish anything. The plugin is only being used there to pack an npm tarball
d
So my other application has to know the exact location of the npm tarball?
There's no equivalent to Maven local or something?
b
Not in the same sense. You could host a local npm registry server and publish there.
d
Hmm... that's a little trickier. I wonder if there's a way to include the js package as binaries in a maven project. Then import then in my other project. Less tooling dependencies that way.
b
You could with some gradle magic. Jar is just a zip archive so you can shove your npm tarball onto it and then unzip it from jar to project-local dir on the consumer project
d
But maybe more awkward in the long run since eventually I will want to move to using npm. Ok. This has given me something to think about.
Thanks