Gradle, JS, webpack: source maps support
#KT-31013
This commit is contained in:
+9
-2
@@ -13,7 +13,6 @@ import org.gradle.deployment.internal.DeploymentHandle
|
|||||||
import org.gradle.deployment.internal.DeploymentRegistry
|
import org.gradle.deployment.internal.DeploymentRegistry
|
||||||
import org.gradle.process.internal.ExecHandle
|
import org.gradle.process.internal.ExecHandle
|
||||||
import org.gradle.process.internal.ExecHandleFactory
|
import org.gradle.process.internal.ExecHandleFactory
|
||||||
import org.gradle.process.internal.ExecHandleState
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationToRunnableFiles
|
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationToRunnableFiles
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||||
@@ -60,6 +59,9 @@ open class KotlinWebpack : DefaultTask() {
|
|||||||
@Input
|
@Input
|
||||||
var bin: String = "webpack"
|
var bin: String = "webpack"
|
||||||
|
|
||||||
|
@Input
|
||||||
|
var sourceMaps: Boolean = true
|
||||||
|
|
||||||
@Input
|
@Input
|
||||||
@Optional
|
@Optional
|
||||||
var devServer: KotlinWebpackConfig.DevServer? = null
|
var devServer: KotlinWebpackConfig.DevServer? = null
|
||||||
@@ -75,7 +77,8 @@ open class KotlinWebpack : DefaultTask() {
|
|||||||
outputPath,
|
outputPath,
|
||||||
configDirectory,
|
configDirectory,
|
||||||
if (report) reportDir else null,
|
if (report) reportDir else null,
|
||||||
devServer
|
devServer,
|
||||||
|
sourceMaps = sourceMaps
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -117,6 +120,10 @@ open class KotlinWebpack : DefaultTask() {
|
|||||||
runtimeOnly(npm("webpack", "4.29.6"))
|
runtimeOnly(npm("webpack", "4.29.6"))
|
||||||
runtimeOnly(npm("webpack-cli", "3.3.0"))
|
runtimeOnly(npm("webpack-cli", "3.3.0"))
|
||||||
runtimeOnly(npm("webpack-bundle-analyzer", "3.3.2"))
|
runtimeOnly(npm("webpack-bundle-analyzer", "3.3.2"))
|
||||||
|
|
||||||
|
// for source map support only
|
||||||
|
runtimeOnly(npm("source-map-loader", "0.2.4"))
|
||||||
|
runtimeOnly(npm("source-map-support", "0.5.12"))
|
||||||
}
|
}
|
||||||
|
|
||||||
project.createOrRegisterTask<KotlinWebpack>("webpack") {
|
project.createOrRegisterTask<KotlinWebpack>("webpack") {
|
||||||
|
|||||||
+24
-6
@@ -21,7 +21,8 @@ class KotlinWebpackConfig(
|
|||||||
val configDirectory: File,
|
val configDirectory: File,
|
||||||
val reportDir: File?,
|
val reportDir: File?,
|
||||||
var devServer: DevServer? = null,
|
var devServer: DevServer? = null,
|
||||||
val showProgress: Boolean = false
|
val showProgress: Boolean = false,
|
||||||
|
val sourceMaps: Boolean = false
|
||||||
) {
|
) {
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
data class BundleAnalyzerPlugin(
|
data class BundleAnalyzerPlugin(
|
||||||
@@ -54,7 +55,7 @@ class KotlinWebpackConfig(
|
|||||||
"""
|
"""
|
||||||
var config = {
|
var config = {
|
||||||
mode: 'development',
|
mode: 'development',
|
||||||
entry: '${entry.canonicalPath}',
|
entry: ['${entry.canonicalPath}'],
|
||||||
output: {
|
output: {
|
||||||
path: '${outputPath.canonicalPath}',
|
path: '${outputPath.canonicalPath}',
|
||||||
filename: '${entry.name}'
|
filename: '${entry.name}'
|
||||||
@@ -66,12 +67,29 @@ var config = {
|
|||||||
},
|
},
|
||||||
plugins: [],
|
plugins: [],
|
||||||
module: {
|
module: {
|
||||||
rules: []
|
rules: [
|
||||||
}
|
{
|
||||||
};"""
|
test: /\.js${'$'}/,
|
||||||
|
use: ["source-map-loader"],
|
||||||
|
enforce: "pre"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
devtool: 'eval-source-map'
|
||||||
|
};""".trim()
|
||||||
)
|
)
|
||||||
appendln()
|
appendln()
|
||||||
|
|
||||||
|
if (sourceMaps) {
|
||||||
|
//language=JavaScript 1.8
|
||||||
|
appendln("""
|
||||||
|
// source maps
|
||||||
|
config.entry.push('source-map-support/browser-source-map-support.js');
|
||||||
|
config.module.rules.push({test: /\.js${'$'}/, use: ['source-map-loader'], enforce: 'pre'});
|
||||||
|
""".trim())
|
||||||
|
appendln()
|
||||||
|
}
|
||||||
|
|
||||||
if (devServer != null) {
|
if (devServer != null) {
|
||||||
appendln("// dev server")
|
appendln("// dev server")
|
||||||
appendln("config.devServer = ${json(devServer!!)};")
|
appendln("config.devServer = ${json(devServer!!)};")
|
||||||
@@ -80,7 +98,7 @@ var config = {
|
|||||||
|
|
||||||
if (reportDir != null) {
|
if (reportDir != null) {
|
||||||
val reportBasePath = "${reportDir.canonicalPath}/${entry.name}"
|
val reportBasePath = "${reportDir.canonicalPath}/${entry.name}"
|
||||||
val config = KotlinWebpackConfig.BundleAnalyzerPlugin(
|
val config = BundleAnalyzerPlugin(
|
||||||
"static",
|
"static",
|
||||||
"$reportBasePath.report.html",
|
"$reportBasePath.report.html",
|
||||||
false,
|
false,
|
||||||
|
|||||||
Reference in New Issue
Block a user