Robert Munro
07/13/2021, 1:45 PMBig Chungus
07/13/2021, 1:49 PMjw
07/13/2021, 1:51 PMjw
07/13/2021, 1:51 PMRobert Munro
07/13/2021, 1:52 PMBig Chungus
07/13/2021, 1:52 PMRobert Munro
07/13/2021, 1:53 PMBig Chungus
07/13/2021, 1:55 PM//build.gradle.kts
tasks {
val jsProcessResources by getting(Copy::class) {
doLast {
buildDir.resolve("processedResources/js/secrets.json").writeText("""{ "apiKey": "${project.properties["apiKey]}" }""")
}
}
}
//src/jsMain/kotlin/index.kt
external fun require(module:String): dynamic
private val API_KEY = require("./secrets.json").apiKey
Big Chungus
07/13/2021, 1:56 PMbuild/processedResources/js
, but will still be available for kotlin kompiler, thus making kt code workBig Chungus
07/13/2021, 1:58 PMrequire("./secrets.json")
returns const jsObject = {apiKey: "XXXX"}
(that's why you can refer to it by property name on dynamic returnBig Chungus
07/13/2021, 1:59 PMexternal interface Secrets {
val apiKey: String
}
external fun require(module:String): dynamic
private val secrets: Secrets = require("./secrets.json")
private val API_KEY = secrets.apiKey
Robert Munro
07/13/2021, 2:44 PMModule not found: Error: Can't resolve 'secrets.js' in '/Users/robmunro/repos/sentinel/website/build/js/packages/website/kotlin-dce-dev'
Have plyed with json file as well but no matter what the file name i get the same path in the error. Seems like it's not looking a processedResourcesBig Chungus
07/13/2021, 2:46 PMRobert Munro
07/13/2021, 2:53 PMexternal interface Secrets {
val SWEBSITE_MAPS_API_KEY: String
}
external fun require(module:String): dynamic
private val secrets: Secrets = require("./secrets.json")
public val SWEBSITE_MAPS_API_KEY = secrets.SWEBSITE_MAPS_API_KEY
gives
Can't resolve '/secrets.json' in '/Users/robmunro/repos/sentinel/website/build/js/packages/website/kotlin-dce'
Robert Munro
07/13/2021, 2:55 PMkotlin-dce
Big Chungus
07/13/2021, 3:04 PMRobert Munro
07/13/2021, 3:15 PMRobert Munro
07/13/2021, 3:17 PMbrowserProductionWebpack
fails
tasks {
val processResources by getting(Copy::class) {
doLast {
buildDir.resolve("js/packages/website/kotlin-dce-dev/secrets.json")
.writeText("""{"SWEBSITE_MAPS_API_KEY" : "${project.properties["SWEBSITE_MAPS_API_KEY"]}" }""")
}
}
}
but it works for nowBig Chungus
07/14/2021, 11:25 AMprocessedResources/js/main
instead of processedResources/frontend/main
). Ignore all the other configs there, that line is the only one you need.Robert Munro
07/15/2021, 9:34 AM