Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 23 2021 09:24
    @sjrd banned @yensaoxuan_twitter
  • Apr 18 2021 19:06
    @sjrd banned @Amitgup48798297_twitter
  • Mar 29 2021 07:47
    @sjrd banned @quangs
  • Jan 23 2021 06:34
    @sjrd banned @Rebeka58_gitlab
  • Jun 08 2020 20:43
    @sjrd banned @sw7240614
  • Sep 29 2019 08:35
    @sjrd banned @8bitpitRBX_twitter
  • May 23 2019 13:44
    @sjrd banned @BIGCRYPTO001_gitlab
  • May 01 2019 14:31
    @sjrd banned @Certificates1_gitlab
  • Apr 22 2019 15:31
    @sjrd banned @lerbatax
  • Jan 31 2019 23:04
    sjrd commented #3555
  • Jan 31 2019 22:56
    sjrd review_requested #3555
  • Jan 31 2019 22:56
    sjrd opened #3555
  • Jan 31 2019 21:06

    sjrd on 0.6.x

    Remove dead code: specific coll… Adapt the signature of `js.Arra… Merge pull request #3554 from s… (compare)

  • Jan 31 2019 21:06
    sjrd closed #3554
  • Jan 31 2019 20:54
    erikvanoosten commented #2665
  • Jan 31 2019 16:33
    sjrd commented #3538
  • Jan 31 2019 15:54

    sjrd on master

    Fix analyzer cycle detection to… Add toString methods to analyze… Do not provide linked ClassInfo… and 1 more (compare)

  • Jan 31 2019 15:54
    sjrd closed #3552
  • Jan 31 2019 15:54

    sjrd on master

    Remove Logger.success It is un… Make level helpers final Clean-up ScalaConsoleLogger cod… and 1 more (compare)

  • Jan 31 2019 15:54
    sjrd closed #3553
nafg
@nafg
Is there a benefit of sbt-crossproject over sbt-projectmatrix?
Sébastien Doeraene
@sjrd
sbt-projectmatrix is a generalization of sbt-crossproject.
That said, it creates even more projects in the build, so it can slow it down.
nafg
@nafg
@sjrd is that true even for only one scala version, or do you mean that it creates a project per scala version?
Do you mean it slows it down by taking longer to load the build (more settings for sbt to process), or that if it's compiling two scala versions in parallel that can be slower than just one (but still might be faster than compiling the same scala versions via ++)
Sébastien Doeraene
@sjrd
It creates one project per Scala version, yes. It's typically pointless to use project matrix if you don't have multiple Scala versions.
And yes it makes the build slower to load.
nafg
@nafg
That's sbt's major issue still, it seems to be slowed by the huge number of settings it proliferates. And Mill still doesn't seem to have enough plugins for me to switch to it
Mathieu
@mathieuleclaire

Hi,
I am building for a while my scala-js application at runtime because my application is pluggable. I have to be abble to add plugins at runtime or restart the application including new plugins. It use the Linker methods to achieve this (see sources here: https://github.com/openmole/openmole/blob/13-dev/openmole/gui/server/org.openmole.gui.server.jscompile/src/main/scala/org/openmole/gui/server/jscompile/JSPack.scala).

Until now, I dealt with my js lib dependencies by hand, merging js deps in a big js file. But I had often js loading or depencies resolution issues. So I try to use webpack, which is pretty straight forward when everything is compiled and linked from the sbt file. But not really in my case.

My idea was to
1) fastOptJS / webpack an empty project, which depends on the same dependencies as my application (and just calling a couple of fake methods to trigger webpack), so that I get a js file resolving all the js dependencies I need for my main project,
2) build my application with fastOptJS (but with no wepback resolution)
3) merge both js in a big one.
4) compress this big js file (if it is possible afterwards)

The problem is that the main method of the main application is not recognized any more, the html body tag remains empty and nothing happens when the html is run.

Any idea on how to solve my problem ? Is the way I do seems to be the good one ?
Thanks

Sébastien Doeraene
@sjrd
Perhaps you lost scalaJSUseMainModuleInitializer := true in the process?
Mathieu
@mathieuleclaire
Nope, I didn't. Actually, for now I test in separate code to evaluate the feasability. So I fastOptJS a scala code containing a main (with the scalaJSUseMainModuleInitializer := true) and I fastOptJS / webpack my empty project on an other hand. But it should lead to the same result, right ?
Mathieu
@mathieuleclaire
Here is my build:
lazy val emptyProject = project.in(file("packJS")) enablePlugins (ScalaJSBundlerPlugin) dependsOn(ace, bootstrapnative, tools, highlightjs)

lazy val runBootstrapDemo = taskKey[Unit]("runBootsrapDemo")
lazy val bootstrapDemo = project.in(file("bootstrapDemo")) enablePlugins (ScalaJSBundlerPlugin) settings(
  sourceCode,
  scalaJSUseMainModuleInitializer := true,
  runBootstrapDemo := {
    val demoResource = (resourceDirectory in Compile).value
    val deps = (fullOptJS / webpack in emptyProject in Compile).value.head.data
    val jsBuild = (fullOptJS in Compile).value.data

    IO.copyFile(merge(jsBuild, deps), target.value / "js/demobootstrapnative.js")
    IO.copyDirectory(demoResource, target.value)

  }
) dependsOn(ace, bootstrapnative, tools, highlightjs)


def merge(f1: File, in: File) = {
  val from = java.nio.file.Files.lines(in.toPath)
  val bw = new BufferedWriter(new FileWriter(f1))
  from.forEach { p => bw.append(p + "\n") }
  bw.close
  f1
}
Sébastien Doeraene
@sjrd
Does any exception appear in the browser console?
I think your setup will be problematic at least because emptyProject, having no main method, will dead-code-eliminate everything, including its imports from other modules. That in turn will cause Webpack to think that you're not referencing any extra library.
Also Webpack is supposed to rewrite the calls to require in the JS code produced by Scala.js. With your setup, that won't happen.
Mathieu
@mathieuleclaire
I have no exceptions
well, it depends on how I merge it. If I merge jsBuild in deps, I get no exceptions. Otherwise, I get Uncaught ReferenceError: require is not defined
Sébastien Doeraene
@sjrd
If you start your main with a println("hello"), does it get printed?
Mathieu
@mathieuleclaire
nope. The body is empty
I tried to add a App / main in the emptyproject with the same result
Sébastien Doeraene
@sjrd
Hum, your merge function looks like it's trying to append at the end of the file f1, but creating the FileWriter that way will truncate everything in the file before doing anything with it.
You can fix that with new FileWriter(f1, true).
But in general, in sbt it is very bad practice to modify files that are produced by other tasks. It messes up the change detection mechanisms, and things will break.
You should create a third file instead of modifying one of the two files.
Mathieu
@mathieuleclaire
you mean a third file where i merge first 2 ?
Sébastien Doeraene
@sjrd
Yes.
Mathieu
@mathieuleclaire
Now I have Uncaught ReferenceError: require is not defined
with:
def merge(first: File, second: File) = {
  val f1 = java.nio.file.Files.lines(first.toPath)
  val f2 = java.nio.file.Files.lines(second.toPath)
  val in = java.io.File.createTempFile("merge", "JS")
  val bw = new BufferedWriter(new FileWriter(in, true))
  f1.forEach { p => bw.append(p + "\n") }
  f2.forEach { p => bw.append(p + "\n") }
  bw.close
  in
}
Sébastien Doeraene
@sjrd
Well that makes sense to me, given what I said earlier:
Also Webpack is supposed to rewrite the calls to require in the JS code produced by Scala.js. With your setup, that won't happen.
It's possible that ScalaJSBundler's LibraryAndApplication mode could save you.
Mathieu
@mathieuleclaire
Mmh, this does not sound good
Uncaught SyntaxError: redeclaration of class $c_jl_Throwable
note: Previously declared at line 70829, column 6
with :
lazy val emptyProject = project.in(file("packJS")) enablePlugins (ScalaJSBundlerPlugin) settings(
  scalaJSUseMainModuleInitializer := true,
  webpackBundlingMode := LibraryAndApplication()
)dependsOn(ace, bootstrapnative, tools, highlightjs)
Mathieu
@mathieuleclaire
Is it because two mains are merged in the same js ?
Tobias Schlatter
@gzm0
@mathieuleclaire if by that you mean you simply concatenated to Scala.js generated JS, files, then yes.
Ah, but if that build statement you sent is all you did, sounds more like a bug somewhere...
Mathieu
@mathieuleclaire
Yes, it is all I do. In my empyProject, I only invoke libs I need, so that webpack wraps all required js libs:
object PackJS {

  def main(argvs: Array[String]): Unit = {
    def pack = {
      val editorDiv = div(idAttr := "editor")
      ace.edit(editorDiv.ref)
      Tabs.tabs()
      HighlightJS.initHighlightingOnLoad()
    }
  }
}
Tobias Schlatter
@gzm0
How do you include it in your wepage?
(or when do you see the error, when you type run?)
Mathieu
@mathieuleclaire
I don't include it. It is just a trick to webpack all the js I need for my main application, which is built at runtime (plugin system). I tried to explain it before. So, to try to take advantage of the webpack js resolution (which cannot be used in my manual link). To test the feasability, I work in a simpler pattern where I made two projects: my main one with a simple fastOpJS (and no webpacking) and an empty one (depending on the same js dependencies as the main one) to wrap the js required at runtime with webpack. And I try to merge both in a single js.
Tobias Schlatter
@gzm0
Sorry, just saw, there is much more context. Do you still use this merge thing? That will not work except with ModuleKind.NoModule because when you define modules, Scala.js uses the module-level scope for internal definitions.
And then, the second file will define some stuff twice.
You'll need to import the modules individually.

Is it because two mains are merged in the same js ?

So to answer that: It's not that two mains are merged, it's that two linked JS files are merged in the same JS. If you are working with modules, you need to import the two JS files.

Mathieu
@mathieuleclaire
I am still trying this stategy yes. So I should add NoModule in the empty project ?
Sébastien Doeraene
@sjrd
scalajs-bundler forces CommonJSModule and requires it.
TBH I'm not sure scalajs-bundler is fit for what you're trying to do.
Have you considered invoking Webpack yourself?
11 replies
Mathieu
@mathieuleclaire
nope, I am not familiar with js in general and with webpack. It's much more comfortable to use it through scala libs !