[Gradle, JS] esmodules for webpack
This commit is contained in:
+12
-3
@@ -13,6 +13,7 @@ import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.Copy
|
||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDce
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
@@ -153,7 +154,7 @@ abstract class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
task.doNotTrackStateCompat("Tracked by external webpack tool")
|
||||
|
||||
task.commonConfigure(
|
||||
compilation = compilation,
|
||||
binary = binary,
|
||||
mode = mode,
|
||||
inputFilesDirectory = binary.linkSyncTask.flatMap { it.destinationDirectory },
|
||||
entryModuleName = binary.linkTask.flatMap { it.compilerOptions.moduleName },
|
||||
@@ -233,7 +234,7 @@ abstract class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
task.dependsOn(binary.linkSyncTask)
|
||||
|
||||
task.commonConfigure(
|
||||
compilation = compilation,
|
||||
binary = binary,
|
||||
mode = mode,
|
||||
inputFilesDirectory = binary.linkSyncTask.flatMap { it.destinationDirectory },
|
||||
entryModuleName = binary.linkTask.flatMap { it.compilerOptions.moduleName },
|
||||
@@ -267,7 +268,7 @@ abstract class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
}
|
||||
|
||||
private fun KotlinWebpack.commonConfigure(
|
||||
compilation: KotlinJsCompilation,
|
||||
binary: JsIrBinary,
|
||||
mode: KotlinJsBinaryMode,
|
||||
inputFilesDirectory: Provider<File>,
|
||||
entryModuleName: Provider<String>,
|
||||
@@ -285,7 +286,15 @@ abstract class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
|
||||
this.inputFilesDirectory.fileProvider(inputFilesDirectory)
|
||||
|
||||
val platformType = binary.compilation.platformType
|
||||
val moduleKind = binary.linkTask.flatMap { it.compilerOptions.moduleKind }
|
||||
|
||||
this.entryModuleName.set(entryModuleName)
|
||||
this.esModules.set(
|
||||
project.provider {
|
||||
platformType == KotlinPlatformType.wasm || moduleKind.get() == JsModuleKind.MODULE_ES
|
||||
}
|
||||
)
|
||||
|
||||
mainOutputFileName.convention(defaultArchivesName.orElse("main").map { "$it.js" }).finalizeValueOnRead()
|
||||
|
||||
|
||||
+2
@@ -300,6 +300,8 @@ abstract class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
}
|
||||
)
|
||||
|
||||
this.esModules.set(false)
|
||||
|
||||
resolveFromModulesFirst = true
|
||||
|
||||
mainOutputFileName.convention(defaultArchivesName.orElse("main").map { "$it.js" }).finalizeValueOnRead()
|
||||
|
||||
+4
-1
@@ -111,10 +111,13 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
@get:Input
|
||||
abstract val esModules: Property<Boolean>
|
||||
|
||||
@get:Internal
|
||||
val entry: Provider<RegularFile>
|
||||
get() = inputFilesDirectory.map {
|
||||
it.file(entryModuleName.get() + if (platformType == KotlinPlatformType.wasm) ".mjs" else ".js")
|
||||
it.file(entryModuleName.get() + if (esModules.get()) ".mjs" else ".js")
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
Reference in New Issue
Block a user