Christian Williams
04/02/2023, 5:04 AM.js
or .ts
files into src/jsMain/kotlin
and have them auto included in the compiled js module, and perhaps auto-generate kotlin stubs when possible using dukat — more or less mirroring kotlin’s behavior with java in jvm land. I’d be happy to hack that feature into a gradle plugin (or whatever) to hook that all up if someone can verify that functionality doesn’t already exist in some obvious form, and maybe give me some pointers on how to configure such a setup.Big Chungus
04/02/2023, 7:09 AMChristian Williams
04/02/2023, 7:34 AMBig Chungus
04/02/2023, 7:42 AMChristian Williams
04/02/2023, 7:48 AMapp/Index.kt
package app
import app.Foo
import react.*
val Index = FC<Props> {
Foo {}
}
app/Foo.kt
@file:JsModule("Foo") // maybe this should be "../Foo"?
@file:JsNonModule
package app
import react.*
external val Foo: ComponentType<Props>
app/Foo.js
import React from 'react';
const Foo = () => {
return (
<h1>Code from JSX!</h1>
);
};
Fails with:
> Task :jsBrowserDevelopmentWebpack FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':jsBrowserDevelopmentWebpack'.
> Module not found: Error: Can't resolve 'Foo' in '/build/js/packages/baaahs-dot-org/kotlin'
Did you mean './Fooz'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
Big Chungus
04/02/2023, 7:49 AMChristian Williams
04/02/2023, 7:52 AM./kotlin/Foo.js
.Big Chungus
04/02/2023, 8:01 AMChristian Williams
04/02/2023, 8:08 AM.java
files into resources
to get them to be resolvable from jvm kotlin right?
Doesn’t seem to work though actually:@file:JsModule("./Foo.js")
, the external is undefined cuz the file is in js modules as ./kotlin/Foo.js
.
With `@file:JsModule("./kotlin/Foo.js")`:
> Task :jsBrowserDevelopmentWebpack
Module not found: Error: Can't resolve './kotlin/Foo.js' in '.../build/js/packages/baaahs-dot-org/kotlin'
Big Chungus
04/02/2023, 8:34 AMAdam S
04/02/2023, 8:39 AMAnd kotlin dir doesn’t work because gradle only uses .kt(s) files from there and ignores everything else.I’ve not tried it with Kotlin Multiplatform, but you can update the includes/excludes in Gradle source sets to include new files
// build.gradle.kts
kotlin {
js(IR) { ... }
sourceSets {
jsMain {
kotlin.include("**/*.js", "**/*.ts")
}
}
}
^ that might work?Big Chungus
04/02/2023, 9:20 AMChristian Williams
04/02/2023, 6:53 PMBig Chungus
04/02/2023, 7:01 PM