!kcOuJGXBoqBVSCYYAy:matrix.org

Scala JS

2032 Members
Scala.js, the Scala to JavaScript compiler7 Servers

Load older messages


SenderMessageTime
16 Apr 2024
@_discord_231490300219097089:t2bot.ioex0ns I have a question regarding scala.js and sbt, I have a module design that contains components and common UI helpers, it also contains a raw js file (in the resource directory), that is loaded using a JSImport inside one of the file.
I'm using the module (which will be split out from the repository and published as a lib in the future) from another module called frontend however when running fastLinkJS and serving my frontend with vite, it fails to resolve the file.js coming from the design module.
A solution I have found it adding fronted / Compile / unmanagedResources ++= (design / Compile / unamanedResources).value in my build and changing my import to @JSImport("../classes/file.js") which seems to be working, but feels pretty ugly (and I don't know how it will behave when the design module will not be a module but a dependency)

Is there an easier way to perform that ?
08:43:16
@_discord_815546116066115595:t2bot.ionikitaga Relative import paths are resolved by the bundler (Vite or Webpack), not by Scala.js – and so, they are relative to the scala.js output directory, not to the Scala source file in which you do JSImport. So, with that in mind, you can use the correct relative path when JSImport-ing main.js, which I believe should work, or, if you use Vite, I made a plugin that lets you import a single file by glob pattern, e.g. you can say JSImport("@find/**/file.js) and it will find your file.js wherever it is: https://github.com/raquo/vite-plugin-glob-resolver 08:49:54
@_discord_815546116066115595:t2bot.ionikitaga * ex0ns Relative import paths are resolved by the bundler (Vite or Webpack), not by Scala.js – and so, they are relative to the scala.js output directory, not to the Scala source file in which you do JSImport. So, with that in mind, you can use the correct relative path when JSImport-ing main.js, which I believe should work, or, if you use Vite, I made a plugin that lets you import a single file by glob pattern, e.g. you can say JSImport("@find/**/file.js) and it will find your file.js wherever it is: https://github.com/raquo/vite-plugin-glob-resolver 08:50:14
@_discord_435406890562879488:t2bot.iofel_mazo joined the room.08:51:31
@unicorny9205:matrix.orgunicorny9205 joined the room.08:57:33
@_discord_1047877952077037599:t2bot.iomcall7651 joined the room.09:09:42
@_discord_1047877952077037599:t2bot.iomcall7651 I wrote a Scala 3 project depending on this Java library
math.geom2d:javaGeom 0.11.1 (https://search.maven.org/#artifactdetails|math.geom2d|javaGeom|0.11.1|jar)
for performing geometric computations.

I would like to compile my project for scala.js as well.

How can I achieve this result?

* It seems not possible to use the dependency as is in a Scala JS project, if I am not mistaken. Are there solutions to somehow convert it or wrap it?

* Or should I refactor the whole project to depend on a different equivalent Scala library that can be used for Scala JS as well? In case, any suggestion for a replacement?
09:09:43
@_discord_1047877952077037599:t2bot.iomcall7651 changed their display name from _discord_1047877952077037599 to mcall7651.09:09:44
@_discord_1047877952077037599:t2bot.iomcall7651 Asked the same question also here https://users.scala-lang.org/t/scala-js-and-java-geom-library/9930 09:10:10
@_discord_904983475847847967:t2bot.io_gzm0
Are there solutions to somehow convert it or wrap it?

Not that I know of. You'll need to replace it. No suggestions unfortunately 😕
09:11:36
@_discord_1047877952077037599:t2bot.iomcall7651 Thank you _gzm0 this is already a good pointer 09:13:43
@_discord_763261869388857345:t2bot.iodexter.2305 changed their display name from dexter to dexter.2305.09:50:49
@_discord_117714065320706054:t2bot.ioptrdom You could try forking and converting the project of the dependency to Scala. Just at a quick glance at Java geom sources it seems like its core depends on parts of Java that are compatible with Scala and Scala.js. Might be worth it if this library is critical for you and a good deed for the community too 😃 10:54:23
@_discord_448877036098813952:t2bot.ioLorenzo Gabriele (lolgab) Maybe compile it to js wihh TeaVM and then call it as if it was a javascript library? Could such a frankestain work? 11:05:57
@_discord_448877036098813952:t2bot.ioLorenzo Gabriele (lolgab) * Maybe compile it to js with TeaVM and then call it as if it was a javascript library? Could such a frankestain work? 11:06:12
@_discord_448877036098813952:t2bot.ioLorenzo Gabriele (lolgab) Forking and converting to Scala seems a much cleaner and sane option, though, you can get help from Imtellij, since it can transpile java to Scala 11:07:23
@_discord_632729825647525922:t2bot.ioekrich ptrdom I did this file by file on this project - https://github.com/ekrich/sconfig It is quite a bit of work but if you have any questions let me know. 16:24:09
@_discord_561905304372117505:t2bot.iojjmalina set a profile picture.18:44:06
@alexa1234:matrix.orgalexa1234 joined the room.19:46:13
@_discord_519806985668132884:t2bot.iodamianreeves Curious if anyone has an example of using ScalaJS with Bun? 20:49:50
17 Apr 2024
@_discord_1034169728001912952:t2bot.iokawaxte changed their profile picture.00:58:59
@_discord_188304488195424257:t2bot.io_pleb_ joined the room.09:33:04
@_discord_464249676808323073:t2bot.iopismice joined the room.15:42:00
18 Apr 2024
@_discord_730321412962779246:t2bot.iooclok_ joined the room.03:11:10
@_discord_782636610843967509:t2bot.ioloafingb changed their display name from LoafingB to loafingb.10:30:10
@_discord_607268197007097876:t2bot.io3sant joined the room.16:44:59
19 Apr 2024
@_discord_188611596832997385:t2bot.ioarturaz Anyone using ViteJS and knows what's up?

I have a directory structure like this:
/client
  /src # the Scala source code lies here
  /vite
    /index.html
    /scala_output # the JS files are put here


I launch vite from the /client/vite folder.

Now the weird part is that if I edit .scala files in /client/src/ Vite picks it up and reloads the page, even if no JS was actually changed.

For example:
7:28:54 AM [vite] page reload /home/x11/work/.../client/src/app/components/AppMainModal.scala


Why is it doing that and how can I make it not care about the .scala files? 🙂
04:40:47
@_discord_763619119525527588:t2bot.iojysh_ joined the room.05:22:24
@_discord_800021666741747742:t2bot.iosherpal Maybe you can use the server.watch options? https://vitejs.dev/config/server-options.html#server-watch 07:45:52
@_discord_188611596832997385:t2bot.ioarturaz Yup, vite.config.js with this content helped:
/** @type {import('vite').UserConfig} */
export default {
  "server": {
    "watch": {
      "ignored": ["**/*.scala"]
    }
  }
}
08:34:49

There are no newer messages yet.


Back to Room ListRoom Version: 9