[Gradle, JS] Common webpack's configurations

This commit is contained in:
Ilya Goncharov
2019-10-21 19:16:14 +03:00
parent eb7fe6b0a4
commit e3ec37b14f
2 changed files with 16 additions and 6 deletions
@@ -33,6 +33,8 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
KotlinJsSubTarget(target, "browser"), KotlinJsSubTarget(target, "browser"),
KotlinJsBrowserDsl { KotlinJsBrowserDsl {
private val commonWebpackConfigurations: MutableList<KotlinWebpack.() -> Unit> = mutableListOf()
private val commonRunConfigurations: MutableList<KotlinWebpack.() -> Unit> = mutableListOf()
private val dceConfigurations: MutableList<KotlinJsDce.() -> Unit> = mutableListOf() private val dceConfigurations: MutableList<KotlinJsDce.() -> Unit> = mutableListOf()
private lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant> private lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
@@ -47,11 +49,11 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
} }
override fun runTask(body: KotlinWebpack.() -> Unit) { override fun runTask(body: KotlinWebpack.() -> Unit) {
TODO() commonRunConfigurations.add(body)
} }
override fun webpackTask(body: KotlinWebpack.() -> Unit) { override fun webpackTask(body: KotlinWebpack.() -> Unit) {
TODO() commonWebpackConfigurations.add(body)
} }
@ExperimentalDce @ExperimentalDce
@@ -116,6 +118,10 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
it.dependsOn(compileKotlinTask) it.dependsOn(compileKotlinTask)
} }
} }
commonRunConfigurations.forEach { configure ->
it.configure()
}
} }
dceTaskProvider.configure { dceTaskProvider.configure {
@@ -171,6 +177,10 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
it.dependsOn(compileKotlinTask) it.dependsOn(compileKotlinTask)
} }
} }
commonWebpackConfigurations.forEach { configure ->
it.configure()
}
} }
dceTaskProvider.configure { dceTaskProvider.configure {
@@ -198,8 +208,8 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
val kotlinTask = compilation.compileKotlinTask val kotlinTask = compilation.compileKotlinTask
return project.registerTask(dceTaskName) { return project.registerTask(dceTaskName) {
dceConfigurations.forEach { configuration -> dceConfigurations.forEach { configure ->
it.configuration() it.configure()
} }
it.dependsOn(kotlinTask) it.dependsOn(kotlinTask)
@@ -56,8 +56,8 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
var entry: File? = null var entry: File? = null
get() = field ?: compilation.compileKotlinTask.outputFile get() = field ?: compilation.compileKotlinTask.outputFile
@Input @get:Internal
var resolveFromModulesFirst: Boolean = false internal var resolveFromModulesFirst: Boolean = false
@Suppress("unused") @Suppress("unused")
val runtimeClasspath: FileCollection val runtimeClasspath: FileCollection