val x by css {
backgroundImage = require("src/main/resources/image.png")
}
gives an error
Copy code
Module 'src/main/resources/image.png' not found
Moving file to main/kotlin/... and changing to relative path from the source file dir gives the same "not found" error. Using JsModule gives the same error too.
Where should resources be placed, and how to reference them by relative path in kotlin/js react app?
Please, help!
Google gives only 2-year (and more) old advices which don't help, because kotlin/js seems to have changed much recently.
a
andylamax
03/30/2021, 11:18 PM
require("image.png")
a
archana 0623
03/31/2021, 9:02 AM
Even I have the same doubt, referencing via resources does not work..
a
Alexey Artemiev
03/31/2021, 5:40 PM
@andylamax, tried, doesn't work either.
Copy code
Module 'image.png' not found
The image file resides both in
resources
, and in sources near .kt file. Neither helps.
a
andylamax
03/31/2021, 8:05 PM
do you have webpack setup correctly? you should have seen a different error about loaders. Also, it just have to reside in
resources
it doesn't work near
.kt
a
Alexey Artemiev
04/03/2021, 7:07 PM
I managed to add resources to module search path, and possibly to load PNG through file-loader.
But the overall result is fail 🙂
It is not converted to anything PNG-like. Like reachable relative url or data url (like create-react-app does).
I guess I do smth basically wrong...
Alexey Artemiev
04/03/2021, 8:38 PM
kotlin-styled
package attracts me with its type-safe approach and Kotlin DSL way,
but possibly I should start with simple CSS usage, and with learning webpack...
Before create-react-app handled all this magic smoothly. :)