'Setting output path for Kotlin/JS distribution / webpack output
When building my project using the browserDistribution Gradle task, Kotlin/JS puts the output which has been processed by webpack into /build/distributions/myProject.js.
Instead, I would like my output to go into a folder called /output in my project's root directory.
How can I change the path where my distributions are put after running through webpack?
I'm using the Gradle Kotlin DSL if that helps.
Solution 1:[1]
The Kotlin/JS Gradle plugin provides a distribution API which can be used to adjust the output directory of a project. To put the final distribution output of a project into a folder called output in the project root, one can use the following snippet (it works in both Gradle Kotlin DSL and Groovy Gradle):
browser {
distribution {
directory = file("$projectDir/output/")
}
}
Solution 2:[2]
The output path can be set via the outputPath property in the commonWebpackConfig or the destinationDirectory property in the webpackTask block , e.g.:
// kotlin dsl
kotlin {
js {
binaries.executable()
browser {
// either configure here
commonWebpackConfig {
outputPath = file("$projectDir/build/distributions/assets/js")
}
// or here
webpackTask {
destinationDirectory = file("$projectDir/build/distributions/assets/js")
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sebastian A. |
| Solution 2 | Stefan |
