3

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.

Sebastian A.
  • 402
  • 2
  • 9

2 Answers2

2

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/")
    }
}
Sebastian A.
  • 402
  • 2
  • 9
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")
            }
        }
    }
}

Stefan
  • 1,029
  • 9
  • 21