scalacenter / scalajs-bundler

https://scalacenter.github.io/scalajs-bundler
Other
235 stars 101 forks source link

regression since 0.17 bundling resources from separate module #403

Closed evbo closed 3 years ago

evbo commented 3 years ago

Hi,

I use sbt-buildinfo to generate source containing an object with different constants depending on environment (e.g. "dev" vs "prod").

To facilitate this, I have a simple "client" project that my "dev" version extends from by directly referencing its source:


lazy val client = project.in(file("client"))
  // client used for tests and development so IDE can track managedSources in usual directories inside project folder
  .dependsOn(core.js)
  .enablePlugins(BuildInfoPlugin)
  .enablePlugins(ScalaJSBundlerPlugin)
  .settings(Dependencies.client)

lazy val clientDev = project.in(file("client-dev"))
  .dependsOn(core.js)
  .enablePlugins(BuildInfoPlugin)
  .enablePlugins(ScalaJSBundlerPlugin)
  .settings(clientModuleSources)
  .settings( Dependencies.client)
  .settings(
    buildInfoKeys := Seq[BuildInfoKey](
      "uri" -> "some-dev-server"
    )
  )

// the above module has no code of its own, it merely sets buildInfoKeys and otherwise references all of client's code here:
lazy val clientModuleSources = Seq(
  sourceDirectory in Compile := sourceDirectory.in(client, Compile).value,
  resourceDirectory in Compile := resourceDirectory.in(client, Compile).value
)

This used to work with scala 2.12 and scalajs-bundler 0.17.0, where it would correctly bundle the sources and resources from client, but now my target directory under client-dev does not contain any resources under the target/scala.2.13/scalajs-bundler/main sub directory. The resources are correctly populated in target/scala.2.13/classes however.

How could scalajs-bundler not copy correctly into the scalajs-bundler/main directory if my Dependencies.client says to do so with?:

webpackResources := resourceDirectory.in(Compile).value ** "*" filter { _.isFile },

webpackConfigFile in fastOptJS := Some(resourceDirectory.in(Compile).value / "webpack" / "webpack-fastopt.config.js"),
webpackConfigFile in fullOptJS := Some(resourceDirectory.in(Compile).value / "webpack" / "webpack-fullopt.config.js"),

Every resource is bundled fine as expected for just building client, which doesn't have any buildInfo and doesn't try to set the resource or source directories.

evbo commented 3 years ago

my mistake, it seems sbt clean was not doing it's job, or I'm not triggering it correctly? I had to manually delete all target directories and then it worked.