Hi there - I want to build an Alfred workflow with...
# javascript
v
Hi there - I want to build an Alfred workflow with kotlin, and I want to use https://github.com/sindresorhus/alfy library to do so. It’s my first time doing something meaningful with KotlinJs and I’m really confused on how to create a kotlin js app that would depend on npm module. Is there a good example/guide somewhere I can use?
r
v
I’ve been looking into that, but I don’t find the provided examples very useful/comprehensible .
but I’m not sure how the actual external dependencies used
also I was not able to run the tests - Intellij does not understand test file as test file, and the gradle commands that seem relevant don’t seem to be doing anything
I’m looking at https://medium.com/@Miqubel/your-first-node-js-app-with-kotlin-30e07baa0bf7 now, it seems to involve semi manual npm dependency management, but it’s at least somewhat more clear on how to actually use npm dependency
r
With kotlin-gradle-plugin you can add npm dependencies into your build.gradle with npm { } DSL, e.g.:
Copy code
npm {
        dependency("hammerjs", "2.0.8")
    }
Next you can use
require
command in your kotlin code e.g.:
Copy code
val hammer = require("hammerjs")
        val hammerjs = hammer(document.body)
        hammerjs.on("swiperight") {
            // ...
        }
        hammerjs.on("swipeleft") {
            // ...
        }
Tests are run by Karma so you can view results in your browser. This plugin works with webpack HMR, so it's really productive for the developer. There are some issues with kotlin-frontend-plugin, but i'm using it almost all the time without major problems.
v
ok, let me try this once again and get back to you with more specific questions
r
You can also check examples apps for my project at https://github.com/rjaros/kvision-examples - almost all of them are build with kotlin-frontend-plugin.
👍 1
c
i wrote this a while back when learning kotlin js, might be of some use to you: https://medium.com/@chris.barbour03/kotlin-js-building-deploying-and-depending-on-it-with-npm-and-webpack-2f7aab544c9f
❤️ 2
v
Thanks, I managed to make kotlin-frontend-plugin to work
👍 1