[Gradle, JS] Divide values for devtool (source maps)
This commit is contained in:
+23
-5
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.Devtool
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.Mode
|
||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
@@ -67,7 +68,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
||||
)
|
||||
|
||||
it.mode = Mode.DEVELOPMENT
|
||||
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
||||
it.compilation = compilation
|
||||
it.description = "start webpack dev server"
|
||||
@@ -102,10 +102,19 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
compileKotlinTask
|
||||
)
|
||||
|
||||
it.mode = when (buildVariant.kind) {
|
||||
BuildVariantKind.RELEASE -> Mode.PRODUCTION
|
||||
BuildVariantKind.DEBUG -> Mode.DEVELOPMENT
|
||||
}
|
||||
val kind = buildVariant.kind
|
||||
|
||||
it.mode = getByKind(
|
||||
kind = kind,
|
||||
releaseValue = Mode.PRODUCTION,
|
||||
debugValue = Mode.DEVELOPMENT
|
||||
)
|
||||
|
||||
it.devtool = getByKind(
|
||||
kind = kind,
|
||||
releaseValue = Devtool.SOURCE_MAP,
|
||||
debugValue = Devtool.EVAL_SOURCE_MAP
|
||||
)
|
||||
|
||||
it.compilation = compilation
|
||||
it.description = "build webpack bundle"
|
||||
@@ -115,6 +124,15 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> getByKind(
|
||||
kind: BuildVariantKind,
|
||||
releaseValue: T,
|
||||
debugValue: T
|
||||
): T = when (kind) {
|
||||
BuildVariantKind.RELEASE -> releaseValue
|
||||
BuildVariantKind.DEBUG -> debugValue
|
||||
}
|
||||
|
||||
override fun configureBuildVariants() {
|
||||
buildVariants = project.container(BuildVariant::class.java)
|
||||
buildVariants.create(RELEASE) {
|
||||
|
||||
+5
-1
@@ -49,7 +49,7 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
||||
}
|
||||
|
||||
@Input
|
||||
var mode: Mode = Mode.PRODUCTION
|
||||
var mode: Mode = Mode.DEVELOPMENT
|
||||
|
||||
@get:PathSensitive(PathSensitivity.ABSOLUTE)
|
||||
@get:InputFile
|
||||
@@ -108,6 +108,9 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
||||
@Optional
|
||||
var devServer: KotlinWebpackConfig.DevServer? = null
|
||||
|
||||
@Input
|
||||
var devtool: KotlinWebpackConfig.Devtool = KotlinWebpackConfig.Devtool.EVAL_SOURCE_MAP
|
||||
|
||||
private fun createRunner() = KotlinWebpackRunner(
|
||||
compilation.npmProject,
|
||||
configFile,
|
||||
@@ -122,6 +125,7 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
||||
configDirectory = configDirectory,
|
||||
bundleAnalyzerReportDir = if (report) reportDir else null,
|
||||
devServer = devServer,
|
||||
devtool = devtool,
|
||||
sourceMaps = sourceMaps
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user