Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImporting native js modules for side effects only #4156
Comments
You don't necessarily need a dummy variable. It's OK to only refer to the object as a statement, for example in your private val dummy = RawMwcButton you can equally write just RawMwcButton There is no better way to do this. Since Scala.js only reaches external AFAICT, it's also not really possible to change Scala.js to make this any different. Much of the specification relies on having no real entry points besides |
Could we allow local native objects/classes so that this can be hidden away? (maybe even with a macro library)? def loadMwc(): Unit = {
@js.native
@JSImport("@material/mwc-button", JSImport.Default)
object RawMwcButton extends js.Object
RawMwcButton
} |
It can already be hidden away by making it |
Ah, fair enough. Although that wouldn't work with a def macro. But not sure that is actually necessary. |
There does not appear to be a way to do the JS equivalent of
import 'foo';
in Scala.js. Our workaround is this pattern:If we don't have the dummy variable, object gets optimized out and import never happens.
Is there / should there be a better way to do this?