In kotlin jvm (or in java, for what it matter) one can read resource content through the resource input stream.
Is there a way to do it in kotlin js? Right now I'm requesting the resource with an ajax call but It would be best to have the resources automatically embedded in the compiled javascript to avoid further server roundtrips. I'm aware of the triple quote string literal but It's not what I'm looking for.
Thanks for your suggestions
You may add embedded data to javascript file by webpack
.
For example:
1) add file test.json
to directory src/main/resources
with content:
{
"test123": 123
}
2) add directory src/main/resources
to be resolve modules in webpack
:
resolve: {
modules: [
path.resolve("src/main/resources")
]
}
3) add to main method code:
//require is external function: "external val require: dynamic"
println(JSON.stringify(require("test.json")))
And in output you will see: {"test123":123}
If you open webpack bundle, you will see that full file content of test.json
is embedded to it like this:
function(t){t.exports={test123:123}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With