[Gradle, JS] Compatibility breaking changes for css and scss support
This reverts commit 487e854f60.
^KT-53367 fixed
This commit is contained in:
+2
-2
@@ -13,10 +13,10 @@ kotlin {
|
||||
browser {
|
||||
commonWebpackConfig {
|
||||
cssSupport {
|
||||
enabled = true
|
||||
enabled.set(true)
|
||||
}
|
||||
scssSupport {
|
||||
enabled = true
|
||||
enabled.set(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -16,7 +16,7 @@ abstract class CustomWebpackRule
|
||||
@javax.inject.Inject
|
||||
constructor(name: String) : org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackRule(name) {
|
||||
init {
|
||||
test = "none"
|
||||
test.set("none")
|
||||
}
|
||||
override fun loaders() = listOf<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackRule.Loader>()
|
||||
}
|
||||
@@ -26,10 +26,10 @@ kotlin {
|
||||
browser {
|
||||
webpackTask {
|
||||
cssSupport {
|
||||
enabled = true
|
||||
enabled.set(true)
|
||||
}
|
||||
scssSupport {
|
||||
enabled = true
|
||||
enabled.set(true)
|
||||
}
|
||||
rules {
|
||||
rule<CustomWebpackRule>("custom")
|
||||
|
||||
+2
-14
@@ -8,6 +8,8 @@
|
||||
package org.jetbrains.kotlin.gradle.targets.js.webpack
|
||||
|
||||
import com.google.gson.GsonBuilder
|
||||
import org.gradle.api.ExtensiblePolymorphicDomainObjectContainer
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.Nested
|
||||
@@ -70,20 +72,6 @@ data class KotlinWebpackConfig(
|
||||
@Input
|
||||
val webpackMajorVersion: WebpackMajorVersion = WebpackMajorVersion.V5
|
||||
) : WebpackRulesDsl {
|
||||
@get:Internal
|
||||
@Deprecated("use cssSupport methods instead")
|
||||
var cssSupport: KotlinWebpackCssRule
|
||||
get() = rules.maybeCreate("css", KotlinWebpackCssRule::class.java)
|
||||
set(value) {
|
||||
rules.maybeCreate("css", KotlinWebpackCssRule::class.java).apply {
|
||||
this.mode = value.mode
|
||||
this.enabled = value.enabled
|
||||
this.test = value.test
|
||||
this.include = value.include
|
||||
this.exclude = value.exclude
|
||||
}
|
||||
}
|
||||
|
||||
@get:Input
|
||||
@get:Optional
|
||||
val entryInput: String?
|
||||
|
||||
+8
-5
@@ -25,12 +25,15 @@ typealias KotlinWebpackCssSupport = KotlinWebpackCssRule
|
||||
@Suppress("LeakingThis")
|
||||
abstract class KotlinWebpackCssRule @Inject constructor(name: String) : KotlinWebpackRule(name) {
|
||||
@get:Input
|
||||
var mode: String = INLINE
|
||||
abstract val mode: Property<String>
|
||||
|
||||
override var test: String = "/\\.css\$/"
|
||||
init {
|
||||
mode.convention(INLINE)
|
||||
test.convention("/\\.css\$/")
|
||||
}
|
||||
|
||||
override fun validate(): Boolean {
|
||||
if (mode !in arrayOf(EXTRACT, INLINE, IMPORT)) {
|
||||
if (mode.get() !in arrayOf(EXTRACT, INLINE, IMPORT)) {
|
||||
error(
|
||||
"""
|
||||
Possible values for cssSupport.mode:
|
||||
@@ -46,7 +49,7 @@ abstract class KotlinWebpackCssRule @Inject constructor(name: String) : KotlinWe
|
||||
override fun dependencies(versions: NpmVersions): Collection<RequiredKotlinJsDependency> {
|
||||
return mutableListOf<RequiredKotlinJsDependency>().apply {
|
||||
add(versions.cssLoader)
|
||||
when (mode) {
|
||||
when (mode.get()) {
|
||||
EXTRACT -> add(versions.miniCssExtractPlugin)
|
||||
INLINE -> add(versions.styleLoader)
|
||||
IMPORT -> add(versions.toStringLoader)
|
||||
@@ -54,7 +57,7 @@ abstract class KotlinWebpackCssRule @Inject constructor(name: String) : KotlinWe
|
||||
}
|
||||
}
|
||||
|
||||
override fun loaders(): List<Loader> = when (mode) {
|
||||
override fun loaders(): List<Loader> = when (mode.get()) {
|
||||
EXTRACT -> listOf(
|
||||
Loader(
|
||||
loader = "MiniCssExtractPlugin.loader",
|
||||
|
||||
+12
-8
@@ -20,24 +20,28 @@ import javax.inject.Inject
|
||||
@Suppress("LeakingThis")
|
||||
abstract class KotlinWebpackRule @Inject constructor(private val name: String) : Named {
|
||||
@get:Input
|
||||
var enabled: Boolean = false
|
||||
abstract val enabled: Property<Boolean>
|
||||
|
||||
/**
|
||||
* Raw rule `test` field value. Needs to be wrapped in quotes when using string notation.
|
||||
*/
|
||||
@get:Input
|
||||
abstract var test: String
|
||||
abstract val test: Property<String>
|
||||
|
||||
@get:Input
|
||||
var include: MutableList<String> = mutableListOf()
|
||||
abstract val include: ListProperty<String>
|
||||
|
||||
@get:Input
|
||||
var exclude: MutableList<String> = mutableListOf()
|
||||
abstract val exclude: ListProperty<String>
|
||||
|
||||
@get:Input
|
||||
protected open val description: String
|
||||
get() = (this::class.simpleName?.removeSuffix("_Decorated") ?: "KotlinWebpackRule") + "[${getName()}]"
|
||||
|
||||
init {
|
||||
enabled.convention(false)
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the rule state just before it getting applied.
|
||||
* Returning false will skip the rule silently. To terminate the build instead, throw an error.
|
||||
@@ -55,7 +59,7 @@ abstract class KotlinWebpackRule @Inject constructor(private val name: String) :
|
||||
protected abstract fun loaders(): List<Loader>
|
||||
|
||||
@get:Internal
|
||||
internal val active: Boolean get() = enabled && validate()
|
||||
internal val active: Boolean get() = enabled.get() && validate()
|
||||
internal fun Appendable.appendToWebpackConfig() {
|
||||
appendLine(
|
||||
"""
|
||||
@@ -83,14 +87,14 @@ abstract class KotlinWebpackRule @Inject constructor(private val name: String) :
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
val excluded = exclude.takeIf(List<*>::isNotEmpty)
|
||||
val excluded = exclude.get().takeIf(List<*>::isNotEmpty)
|
||||
?.joinToString(separator = ",", prefix = "[", postfix = "]") ?: "undefined"
|
||||
val included = include.takeIf(List<*>::isNotEmpty)
|
||||
val included = include.get().takeIf(List<*>::isNotEmpty)
|
||||
?.joinToString(separator = ",", prefix = "[", postfix = "]") ?: "undefined"
|
||||
appendLine(
|
||||
"""
|
||||
config.module.rules.push({
|
||||
test: ${test},
|
||||
test: ${test.get()},
|
||||
use: use,
|
||||
exclude: $excluded,
|
||||
include: $included,
|
||||
|
||||
+3
-1
@@ -11,7 +11,9 @@ import javax.inject.Inject
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
abstract class KotlinWebpackScssRule @Inject constructor(name: String) : KotlinWebpackCssRule(name) {
|
||||
override var test: String = "/\\.(scss|sass)\$/"
|
||||
init {
|
||||
test.convention("/\\.(scss|sass)\$/")
|
||||
}
|
||||
|
||||
override fun dependencies(versions: NpmVersions): Collection<RequiredKotlinJsDependency> {
|
||||
return super.dependencies(versions) + versions.sass + versions.sassLoader
|
||||
|
||||
Reference in New Issue
Block a user