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.
If you are attempting to set the output directory in order to include the build artifacts into another project, say a backend project running ktor that needs to serve the client build artifacts, then setting the output directory directly is the wrong approach.
In order to be safe to share between projects and allow maximum performance during the build (parallelism), such artifacts must be exposed via Gradle's "outgoing configurations" mechanism.
In the client (producer) project definition, declare a
browserDist
configuration like this:and in the same project declare that the output directory of the
jsBrowserDistribution
task should be inluded in the artifacts of this configuration:Then, in the backend (consumer) project definition, declare a
browserDist
configuration like this:and specify the dependencies of this configuration (change
:client
to the name of the project containing the client build artifacts):and then finally register a task to copy the artifacts and serve them up. For example, for a ktor server, we'll want to copy the artifacts into a
resources/web
directory so they can be served viasinglePageApplication
.In the backend build, define:
In ktor, define a route like this:
Adjust as necessary for your specific backend.