[Gradle, JS] Compatibility changes for css and scss support
This commit is contained in:
+2
-2
@@ -13,10 +13,10 @@ kotlin {
|
||||
browser {
|
||||
commonWebpackConfig {
|
||||
cssSupport {
|
||||
enabled.set(true)
|
||||
enabled = true
|
||||
}
|
||||
scssSupport {
|
||||
enabled.set(true)
|
||||
enabled = 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.set("none")
|
||||
test = "none"
|
||||
}
|
||||
override fun loaders() = listOf<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackRule.Loader>()
|
||||
}
|
||||
@@ -26,10 +26,10 @@ kotlin {
|
||||
browser {
|
||||
webpackTask {
|
||||
cssSupport {
|
||||
enabled.set(true)
|
||||
enabled = true
|
||||
}
|
||||
scssSupport {
|
||||
enabled.set(true)
|
||||
enabled = true
|
||||
}
|
||||
rules {
|
||||
rule<CustomWebpackRule>("custom")
|
||||
|
||||
+14
-2
@@ -8,8 +8,6 @@
|
||||
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
|
||||
@@ -72,6 +70,20 @@ 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?
|
||||
|
||||
+5
-8
@@ -25,15 +25,12 @@ typealias KotlinWebpackCssSupport = KotlinWebpackCssRule
|
||||
@Suppress("LeakingThis")
|
||||
abstract class KotlinWebpackCssRule @Inject constructor(name: String) : KotlinWebpackRule(name) {
|
||||
@get:Input
|
||||
abstract val mode: Property<String>
|
||||
var mode: String = INLINE
|
||||
|
||||
init {
|
||||
mode.convention(INLINE)
|
||||
test.convention("/\\.css\$/")
|
||||
}
|
||||
override var test: String = "/\\.css\$/"
|
||||
|
||||
override fun validate(): Boolean {
|
||||
if (mode.get() !in arrayOf(EXTRACT, INLINE, IMPORT)) {
|
||||
if (mode !in arrayOf(EXTRACT, INLINE, IMPORT)) {
|
||||
error(
|
||||
"""
|
||||
Possible values for cssSupport.mode:
|
||||
@@ -49,7 +46,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.get()) {
|
||||
when (mode) {
|
||||
EXTRACT -> add(versions.miniCssExtractPlugin)
|
||||
INLINE -> add(versions.styleLoader)
|
||||
IMPORT -> add(versions.toStringLoader)
|
||||
@@ -57,7 +54,7 @@ abstract class KotlinWebpackCssRule @Inject constructor(name: String) : KotlinWe
|
||||
}
|
||||
}
|
||||
|
||||
override fun loaders(): List<Loader> = when (mode.get()) {
|
||||
override fun loaders(): List<Loader> = when (mode) {
|
||||
EXTRACT -> listOf(
|
||||
Loader(
|
||||
loader = "MiniCssExtractPlugin.loader",
|
||||
|
||||
+8
-12
@@ -20,28 +20,24 @@ import javax.inject.Inject
|
||||
@Suppress("LeakingThis")
|
||||
abstract class KotlinWebpackRule @Inject constructor(private val name: String) : Named {
|
||||
@get:Input
|
||||
abstract val enabled: Property<Boolean>
|
||||
var enabled: Boolean = false
|
||||
|
||||
/**
|
||||
* Raw rule `test` field value. Needs to be wrapped in quotes when using string notation.
|
||||
*/
|
||||
@get:Input
|
||||
abstract val test: Property<String>
|
||||
abstract var test: String
|
||||
|
||||
@get:Input
|
||||
abstract val include: ListProperty<String>
|
||||
var include: MutableList<String> = mutableListOf()
|
||||
|
||||
@get:Input
|
||||
abstract val exclude: ListProperty<String>
|
||||
var exclude: MutableList<String> = mutableListOf()
|
||||
|
||||
@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.
|
||||
@@ -59,7 +55,7 @@ abstract class KotlinWebpackRule @Inject constructor(private val name: String) :
|
||||
protected abstract fun loaders(): List<Loader>
|
||||
|
||||
@get:Internal
|
||||
internal val active: Boolean get() = enabled.get() && validate()
|
||||
internal val active: Boolean get() = enabled && validate()
|
||||
internal fun Appendable.appendToWebpackConfig() {
|
||||
appendLine(
|
||||
"""
|
||||
@@ -87,14 +83,14 @@ abstract class KotlinWebpackRule @Inject constructor(private val name: String) :
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
val excluded = exclude.get().takeIf(List<*>::isNotEmpty)
|
||||
val excluded = exclude.takeIf(List<*>::isNotEmpty)
|
||||
?.joinToString(separator = ",", prefix = "[", postfix = "]") ?: "undefined"
|
||||
val included = include.get().takeIf(List<*>::isNotEmpty)
|
||||
val included = include.takeIf(List<*>::isNotEmpty)
|
||||
?.joinToString(separator = ",", prefix = "[", postfix = "]") ?: "undefined"
|
||||
appendLine(
|
||||
"""
|
||||
config.module.rules.push({
|
||||
test: ${test.get()},
|
||||
test: ${test},
|
||||
use: use,
|
||||
exclude: $excluded,
|
||||
include: $included,
|
||||
|
||||
+1
-3
@@ -11,9 +11,7 @@ import javax.inject.Inject
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
abstract class KotlinWebpackScssRule @Inject constructor(name: String) : KotlinWebpackCssRule(name) {
|
||||
init {
|
||||
test.convention("/\\.(scss|sass)\$/")
|
||||
}
|
||||
override var test: String = "/\\.(scss|sass)\$/"
|
||||
|
||||
override fun dependencies(versions: NpmVersions): Collection<RequiredKotlinJsDependency> {
|
||||
return super.dependencies(versions) + versions.sass + versions.sassLoader
|
||||
|
||||
Reference in New Issue
Block a user