[Gradle, JS] Add webpack output
This commit is contained in:
+8
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
|||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
|
import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||||
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.targets.js.webpack.KotlinWebpackOutput.Companion.UMD
|
||||||
import org.jetbrains.kotlin.gradle.testing.internal.reportsDir
|
import org.jetbrains.kotlin.gradle.testing.internal.reportsDir
|
||||||
import org.jetbrains.kotlin.gradle.utils.injected
|
import org.jetbrains.kotlin.gradle.utils.injected
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -75,6 +76,12 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
|||||||
@Input
|
@Input
|
||||||
var saveEvaluatedConfigFile: Boolean = true
|
var saveEvaluatedConfigFile: Boolean = true
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
val output: KotlinWebpackOutput = KotlinWebpackOutput(
|
||||||
|
library = baseConventions?.archivesBaseName,
|
||||||
|
libraryTarget = UMD
|
||||||
|
)
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
@Deprecated("use destinationDirectory instead", ReplaceWith("destinationDirectory"))
|
@Deprecated("use destinationDirectory instead", ReplaceWith("destinationDirectory"))
|
||||||
val outputPath: File
|
val outputPath: File
|
||||||
@@ -129,6 +136,7 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
|||||||
mode = mode,
|
mode = mode,
|
||||||
entry = entry,
|
entry = entry,
|
||||||
reportEvaluatedConfigFile = if (saveEvaluatedConfigFile) evaluatedConfigFile else null,
|
reportEvaluatedConfigFile = if (saveEvaluatedConfigFile) evaluatedConfigFile else null,
|
||||||
|
output = output,
|
||||||
outputPath = destinationDirectory,
|
outputPath = destinationDirectory,
|
||||||
outputFileName = outputFileName,
|
outputFileName = outputFileName,
|
||||||
configDirectory = configDirectory,
|
configDirectory = configDirectory,
|
||||||
|
|||||||
+10
-2
@@ -20,6 +20,7 @@ import java.io.StringWriter
|
|||||||
data class KotlinWebpackConfig(
|
data class KotlinWebpackConfig(
|
||||||
val mode: Mode = Mode.DEVELOPMENT,
|
val mode: Mode = Mode.DEVELOPMENT,
|
||||||
val entry: File? = null,
|
val entry: File? = null,
|
||||||
|
val output: KotlinWebpackOutput? = null,
|
||||||
val outputPath: File? = null,
|
val outputPath: File? = null,
|
||||||
val outputFileName: String? = entry?.name,
|
val outputFileName: String? = entry?.name,
|
||||||
val configDirectory: File? = null,
|
val configDirectory: File? = null,
|
||||||
@@ -205,7 +206,12 @@ data class KotlinWebpackConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun Appendable.appendEntry() {
|
private fun Appendable.appendEntry() {
|
||||||
if (entry == null || outputPath == null) return
|
if (
|
||||||
|
entry == null
|
||||||
|
|| outputPath == null
|
||||||
|
|| output == null
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
val multiEntryOutput = "${outputFileName!!.removeSuffix(".js")}-[name].js"
|
val multiEntryOutput = "${outputFileName!!.removeSuffix(".js")}-[name].js"
|
||||||
|
|
||||||
@@ -223,7 +229,9 @@ data class KotlinWebpackConfig(
|
|||||||
return chunkData.chunk.name === 'main'
|
return chunkData.chunk.name === 'main'
|
||||||
? ${outputFileName.jsQuoted()}
|
? ${outputFileName.jsQuoted()}
|
||||||
: ${multiEntryOutput.jsQuoted()};
|
: ${multiEntryOutput.jsQuoted()};
|
||||||
}
|
},
|
||||||
|
library: "${output.library}",
|
||||||
|
libraryTarget: "${output.libraryTarget}",
|
||||||
};
|
};
|
||||||
|
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.targets.js.webpack
|
||||||
|
|
||||||
|
import org.gradle.api.tasks.Input
|
||||||
|
|
||||||
|
data class KotlinWebpackOutput(
|
||||||
|
@Input var library: String?,
|
||||||
|
@Input var libraryTarget: String?
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
const val UMD = "umd"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user