2

I have just started using Kotlin to produce Javascript, but cannot find a way to change the Javascript output directory.

This is specifically for a nodejs target, and using Gradle with Kotlin script.

There is an example given in the Kotlin docs for a browser target:

kotlin.target.browser {
    distribution {
        directory = File("$projectDir/output/")
    }
}

but there does not seem to be an equivalent for kotlin.target.nodejs

2 Answers2

2

This is now easy (Kotlin 1.40):

https://kotlinlang.org/docs/reference/js-project-setup.html#distribution-target-directory

kotlin {
    js {
        browser {
            distribution {
                directory = File("$projectDir/output/")
            }
        }
        binaries.executable()
        // . . .
    }
}
Nick Bilyk
  • 352
  • 2
  • 8
  • Incredible! I give up and drink coffee, come back 1 hour later and google it again, and here you are! Absolute godsend. I've been scratching my eyes out for a good 4 hours now, and it's a 3-liner. – Hack5 Sep 25 '20 at 20:45
  • 2
    This doesn't actually answer the question btw, it was asking about NodeJS exclusively. Anyway, here is my working solution for _my_ issue, based off this answer - https://gitlab.com/-/snippets/2019246. Thanks so much! – Hack5 Sep 25 '20 at 21:03
  • whoops.. I was searching for the browser solution myself and this came up as the first result. Didn't read carefully enough. Your snippet looks like it's also browser unless I'm missing something. – Nick Bilyk Sep 27 '20 at 13:39
  • Yep, my snippet also doesn't answer the question :P. It just solves the same problem you had, from what I can see. – Hack5 Sep 27 '20 at 16:05
1

Unfortunately, there are no possibilities to do this with NodeJS. I created an issue - https://youtrack.jetbrains.com/issue/KT-40416.

vanyochek
  • 815
  • 4
  • 10