Is there any way to associate multiple `requires` ...
# javascript
s
Is there any way to associate multiple
requires
with a single wrapper file? For example, the
swagger-ui
, which is bundled with
swagger-ui/dist/swagger.css
. The CSS should always be required whenever the
swagger-ui
export is required. AFAIK you can only have a single
@file:JsModule(...)
annotation.
s
Sure. You can have multiple `external object`s in a single file with
@JsModule
on them.
s
Right, but not file-wide. What is the implication of annotating an object with @JsModule? Any usage causes the compiler to add that
require
?
s
Yep, they will be `require`d in CommonJS
s
Thank you!
s
Another option is to have separate files for each
@JsModule
😉
s
@Svyatoslav Kuzmich [JB] I'm getting
This annotation is not repeatable
. Is that a bug?
s
I would need some context. What is your annotation usage look like?
Are you using multiple
@JsModule
on the same declaration?
s
Yes. It looks like
@JsModule
does not have the
@Repeatable
annotation.
Copy code
@JsModule("swagger-ui")
@JsModule("swagger-ui/dist/swagger-ui.css")
external interface SwaggerUI {
...
}
s
@Sam Garfinkel Sorry, I was misleading you. I don't know much about webpack, and didn't immediately understand what you want to do.
@JsModule
is meant to import JS modules, it isn't a general replacement for
require
.
s
@Svyatoslav Kuzmich [JB] That's alright, I believe the correct thing here is to use the
kotlinext.js.require
function, although to be fair this is a fairly common use case in webpack. Common enough it would be nice to have something first-class for it.
d
@Sam Garfinkel Did you manage to get this working. If so could you please share the solution. Thanks
s
@Darren Bell Yes, just use
const fooCss = kotlinext.js.require("foo.css")
, or if its associated with, say, a react component, put it in the init block for that component