Including custom files in JS library

If you configure binaries.library() in js(IR), the build will produce build/productionLibrary/ with the files needed to publish the library to NPM. The package.json in it can be customized. However, NPM packages typically also include README, LICENSE and potentially other files. Can these be added to the package without configuring a custom copy task?

js(IR) {
      // ...
      binaries.library()
      compilations["main"].packageJson {
          customField("foo", "bar")
      }
      // Something like this:
      compilations["main"].files(files("README.md", "LICENSE.txt")) // Does not actually compile.
  }
1 Like

jsNodeProductionLibraryDistribution is a Copy task, so you can actually just configure it to include additional files:

tasks.named<Copy>("jsNodeProductionLibraryDistribution") {
  from("README.md", "LICENSE.txt")
}

Ideally there would be a more explicit way to do this with the DSL, but this should be reliable enough, as it will fail if jsNodeProductionLibraryDistribution goes away or becomes a non-Copy task.

1 Like