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