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