[Gradle, JS] Provide entry for DCE to webpack
This commit is contained in:
+20
-8
@@ -31,7 +31,8 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
KotlinJsSubTarget(target, "browser"),
|
KotlinJsSubTarget(target, "browser"),
|
||||||
KotlinJsBrowserDsl {
|
KotlinJsBrowserDsl {
|
||||||
|
|
||||||
lateinit var dceTask: TaskProvider<KotlinJsDce>
|
private val dceWebpackEntryAppliers: MutableList<KotlinJsDce.(File) -> Unit> = mutableListOf()
|
||||||
|
private lateinit var dceTaskProvider: TaskProvider<KotlinJsDce>
|
||||||
|
|
||||||
lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
||||||
|
|
||||||
@@ -59,8 +60,8 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
val project = compilation.target.project
|
val project = compilation.target.project
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
val dceTask = if (::dceTask.isInitialized) {
|
val dceTaskProvider = if (::dceTaskProvider.isInitialized) {
|
||||||
this.dceTask
|
this.dceTaskProvider
|
||||||
} else {
|
} else {
|
||||||
configureDce(compilation)
|
configureDce(compilation)
|
||||||
}
|
}
|
||||||
@@ -96,8 +97,11 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
|
|
||||||
when (kind) {
|
when (kind) {
|
||||||
BuildVariantKind.RELEASE -> {
|
BuildVariantKind.RELEASE -> {
|
||||||
|
dceWebpackEntryAppliers.add { file ->
|
||||||
|
it.entry = file
|
||||||
|
}
|
||||||
it.resolveFromModulesFirst = true
|
it.resolveFromModulesFirst = true
|
||||||
it.dependsOn(dceTask)
|
it.dependsOn(dceTaskProvider)
|
||||||
}
|
}
|
||||||
BuildVariantKind.DEBUG -> {
|
BuildVariantKind.DEBUG -> {
|
||||||
it.dependsOn(compileKotlinTask)
|
it.dependsOn(compileKotlinTask)
|
||||||
@@ -112,8 +116,8 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
val project = compilation.target.project
|
val project = compilation.target.project
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
val dceTask = if (::dceTask.isInitialized) {
|
val dceTaskProvider = if (::dceTaskProvider.isInitialized) {
|
||||||
this.dceTask
|
this.dceTaskProvider
|
||||||
} else {
|
} else {
|
||||||
configureDce(compilation)
|
configureDce(compilation)
|
||||||
}
|
}
|
||||||
@@ -140,8 +144,11 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
|
|
||||||
when (kind) {
|
when (kind) {
|
||||||
BuildVariantKind.RELEASE -> {
|
BuildVariantKind.RELEASE -> {
|
||||||
|
dceWebpackEntryAppliers.add { file ->
|
||||||
|
it.entry = file
|
||||||
|
}
|
||||||
it.resolveFromModulesFirst = true
|
it.resolveFromModulesFirst = true
|
||||||
it.dependsOn(dceTask)
|
it.dependsOn(dceTaskProvider)
|
||||||
project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).dependsOn(it)
|
project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).dependsOn(it)
|
||||||
}
|
}
|
||||||
BuildVariantKind.DEBUG -> {
|
BuildVariantKind.DEBUG -> {
|
||||||
@@ -170,9 +177,14 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
it.classpath = project.configurations.getByName(compilation.compileDependencyConfigurationName)
|
it.classpath = project.configurations.getByName(compilation.compileDependencyConfigurationName)
|
||||||
it.destinationDir = it.dceOptions.outputDirectory?.let { File(it) }
|
it.destinationDir = it.dceOptions.outputDirectory?.let { File(it) }
|
||||||
?: compilation.npmProject.dir.resolve(DCE_DIR)
|
?: compilation.npmProject.dir.resolve(DCE_DIR)
|
||||||
|
|
||||||
|
dceWebpackEntryAppliers.forEach { entryApplier ->
|
||||||
|
it.entryApplier(it.destinationDir.resolve(kotlinTask.outputFile.name))
|
||||||
|
}
|
||||||
|
|
||||||
it.source(kotlinTask.outputFile)
|
it.source(kotlinTask.outputFile)
|
||||||
}.also {
|
}.also {
|
||||||
dceTask = it
|
dceTaskProvider = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -53,8 +53,8 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
|||||||
|
|
||||||
@get:PathSensitive(PathSensitivity.ABSOLUTE)
|
@get:PathSensitive(PathSensitivity.ABSOLUTE)
|
||||||
@get:InputFile
|
@get:InputFile
|
||||||
val entry: File
|
var entry: File? = null
|
||||||
get() = compilation.compileKotlinTask.outputFile
|
get() = field ?: compilation.compileKotlinTask.outputFile
|
||||||
|
|
||||||
@Input
|
@Input
|
||||||
var resolveFromModulesFirst: Boolean = false
|
var resolveFromModulesFirst: Boolean = false
|
||||||
@@ -96,7 +96,7 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
|||||||
var report: Boolean = false
|
var report: Boolean = false
|
||||||
|
|
||||||
open val reportDir: File
|
open val reportDir: File
|
||||||
@OutputDirectory get() = project.reportsDir.resolve("webpack").resolve(entry.nameWithoutExtension)
|
@OutputDirectory get() = project.reportsDir.resolve("webpack").resolve(entry!!.nameWithoutExtension)
|
||||||
|
|
||||||
open val evaluatedConfigFile: File
|
open val evaluatedConfigFile: File
|
||||||
@OutputFile get() = reportDir.resolve("webpack.config.evaluated.js")
|
@OutputFile get() = reportDir.resolve("webpack.config.evaluated.js")
|
||||||
|
|||||||
Reference in New Issue
Block a user