scalacenter / scalajs-bundler

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

Copy directories in webpackResources #322

Closed joan38 closed 4 years ago

joan38 commented 4 years ago

Hi,

I've been trying to do the following lately:

@js.native @JSImport("./images/logo.svg", JSImport.Default)
object LogoSvg extends js.Object

I have the image in src/main/resources/images/logo.svg.

build.sbt:

Compile / npmDevDependencies += "file-loader" -> "5.0.2"
webpackConfigFile := Some(baseDirectory.value / "webpack.config.js")
webpackResources := webpackResources.value +++ PathFinder((Compile / resourceDirectory).value)

webpack.config.js:

var webpack = require('webpack');

module.exports = require('./scalajs.webpack.config');

module.exports.module.rules.push({
  "test": new RegExp("\\.(png|svg|jpg|gif)$"),
  "use": ["file-loader"]
});

And this code change.

Thanks

julienrf commented 4 years ago

Is your problem resolved by putting your logo.svg file into the src/main/js/images/logo.svg path instead? (without changing the value of the webpackResources setting)

joan38 commented 4 years ago

Oh ok, so all the content of src/main/js is actually forwarded to target/scala-x.xx/scalajs-bundler/main? Thanks for the tip, I'm thinking to do a PR to document this.

julienrf commented 4 years ago

Oh ok, so all the content of src/main/js is actually forwarded to target/scala-x.xx/scalajs-bundler/main?

Yes, this is a recent addition that is not yet well documented.

Thanks for the tip, I'm thinking to do a PR to document this.

That would be awesome, thanks!