
seskar.gradle.plugin.ReactLazyComponentFactory.kt Maven / Gradle / Ivy
package seskar.gradle.plugin
// language=javascript
private val IMPORTS = """
import { lazy } from "react"
""".trimIndent()
class ReactLazyComponentFactory :
LazyItemFactory {
override fun create(
data: LazyItemData,
): LazyItem {
val componentName = "${data.name}\$\$__react__lazy__component"
// language=javascript
val body = """
const $componentName = lazy(() =>
import("${data.originalFilePath}")
.then(module => module.${data.export}())
.then(component => ({ default: component }))
)
export const ${data.export} = () => $componentName
""".trimIndent()
return LazyItem(
imports = IMPORTS,
body = body,
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy