gpt4 book ai didi

gradle - 缺少将Kotlin编译为javascript的kotlin.js.map文件

转载 作者:行者123 更新时间:2023-12-03 05:31:58 28 4
gpt4 key购买 nike

我将Kotlin编译为JS,并且效果很好,但是浏览器始终显示错误:

在控制台日志中。

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:63342/engineEmi/web/js/kotlin.js.map



这是我的 build.gradle 文件:
group 'org.example'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin2js'

repositories {
mavenCentral()
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
}

task assembleWeb(type: Sync) {
configurations.compile.each { File file ->
from(zipTree(file.absolutePath), {
includeEmptyDirs = false
include { fileTreeElement ->
def path = fileTreeElement.path
path.endsWith(".js") && (path.startsWith("META-INF/resources/") ||
!path.startsWith("META-INF/"))
}
})
}
compileKotlin2Js {
kotlinOptions.outputFile = "${projectDir}/web/output.js"
kotlinOptions.moduleKind = "plain"
kotlinOptions.sourceMap = true
kotlinOptions.sourceMapEmbedSources = "always"


}

from compileKotlin2Js.destinationDir
into "${projectDir}/web/js"
dependsOn classes
}

task copyHTMLFolder(type: Copy) {
dependsOn assembleWeb
from file("src/html/")
into file("${projectDir}/web/")
}

task openUrlInBrowser {
dependsOn copyHTMLFolder
doLast {
java.awt.Desktop.desktop.browse "http://localhost:63342/engineEmi/web/index.html".toURI()
}
}

assemble.dependsOn assembleWeb

sourceSets {
main.kotlin.srcDirs += 'src/'
main.java.srcDirs += 'src/'
}

我怎样才能让gradle生成kotlin.ja.map文件?

亲切的问候

最佳答案

傻我文件已创建,但未从META-INF复制,因为仅复制了.js文件。

这是assembleWeb Task的工作实现(请参阅带有path.endsWith的条件

task assembleWeb(type: Sync) {
configurations.compile.each { File file ->
from(zipTree(file.absolutePath), {
includeEmptyDirs = false
include { fileTreeElement ->
def path = fileTreeElement.path
(path.endsWith(".js") || path.endsWith(".map")) && (path.startsWith("META-INF/resources/") || !path.startsWith("META-INF/"))
}
})
}
compileKotlin2Js {
kotlinOptions.outputFile = "${projectDir}/web/output.js"
kotlinOptions.moduleKind = "plain"
kotlinOptions.sourceMap = true
kotlinOptions.sourceMapEmbedSources = "always"


}

from compileKotlin2Js.destinationDir
into "${projectDir}/web/js"
dependsOn classes
}

关于gradle - 缺少将Kotlin编译为javascript的kotlin.js.map文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58843979/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com