gpt4 book ai didi

javascript - kotlin-js gradle 输出文件错误

转载 作者:行者123 更新时间:2023-12-03 04:22:47 27 4
gpt4 key购买 nike

我正在研究 kotlin-js 示例。我用过这个sample .当我构建前端模块时(如下图所示)我看不到网络 文件夹。但是资源文件应该在网络 文件夹。怎么了?

Project Source Image

buildscript {
ext.kotlin_version = '1.2.30'

repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

group 'example'
version '1.0-SNAPSHOT'

apply plugin: 'kotlin2js'

repositories {
mavenCentral()
}

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

build.doLast {
configurations.compile.each { File file ->
copy {
includeEmptyDirs = false

from zipTree(file.absolutePath)
into "${projectDir}/web"
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.sourceMap = true
}

最佳答案

您的 copy { ... } block 仅设置从 compile 复制依赖文件配置,并且它不会将您项目的资源复制到web . compileKotlin2Js 也没有任务,它只将编译后的 Kotlin 类放入该目录。

复制main的资源源集,可以再添加一个copy { ... } block ,像这样:

build.doLast {
// ...
copy {
from sourceSets.main.output.resourcesDir
into "${projectDir}/web"
}
}

请注意,如果您只复制文件,您可能会得到上次运行留下的陈旧输出文件(如果源目录中不再存在文件,则不会从目标中删除其副本)。相反,请考虑使用 compileKotlin2Js 的默认输出文件位置。任务和 Sync task同步目录,如 this guide 中所述(它没有提到资源;按照上面的建议将它们添加到 from ... 中)。如果需要自定义输出文件名,可以 use archivesBaseName 为了那个原因。

关于javascript - kotlin-js gradle 输出文件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49265728/

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