You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a library built with ScalaJs, which I'm trying to get running on the iOS JsContext, the problem that I have found is that the @JSExportTopLevel annotation takes no effect unless:
I follow the instructions for the LibraryOnly bundling mode, which depend on the browser window.
I set the LibraryAndApplication bundling mode which depends on the window.
These approaches don't work because iOS doesn't know about such window object, there are previous discussions about removing such window dependency to get this working for node environments (like #205 , #250 )
I have tried to run scalajs generated code without problems, I can likely get every library included manually and generate the JavaScript without the bundler, but it's a bit complex to test and to maintain.
I wonder if there is a workaround to get rid of this window dependency, the docs suggest to add the following code, hopefully there is something similar that doesn't depend on the window:
var exports = window;
exports.require = window["ScalaJSBundlerLibrary"].require;
Thanks!
The text was updated successfully, but these errors were encountered:
As an update, I got the scalajs code produced by the bundler running on iOS by using a global, and the Application bundling mode, this is done by running some code on the main entrypoint, the requirement is to run var Sdk = {}; on iOS before loading the scalajs script.
importscala.scalajs.jsimportscala.scalajs.js.annotation.JSGlobalScope@js.native
@JSGlobalScopeobjectJsGlobalsextends js.Object {
varSdk: js.Dictionary[_] = js.native
}
objectJsSdk {
defmain(args: Array[String]):Unit= {
if (js.typeOf(JsGlobals.Sdk) !="undefined") {
JsGlobals.Sdk= js.Object.fromEntries(
js.Array(
"hello"-> js.Any.fromFunction1(hello)
)
)
} else {
// This means we are out of the iOS environment, where the global is not needed
}
}
defhello(name: String):String= {
s"Hello $name"
}
}
I have a library built with ScalaJs, which I'm trying to get running on the iOS
JsContext
, the problem that I have found is that the@JSExportTopLevel
annotation takes no effect unless:LibraryAndApplication
bundling mode which depends on the window.These approaches don't work because iOS doesn't know about such window object, there are previous discussions about removing such
window
dependency to get this working fornode
environments (like #205 , #250 )I have tried to run scalajs generated code without problems, I can likely get every library included manually and generate the JavaScript without the bundler, but it's a bit complex to test and to maintain.
I wonder if there is a workaround to get rid of this
window
dependency, the docs suggest to add the following code, hopefully there is something similar that doesn't depend on thewindow
:Thanks!
The text was updated successfully, but these errors were encountered: