我正在研究kotlin-js的例子。我用了这个示例。当我构建前端模块(如下图所示)时,我看不到web文件夹。但是资源文件应该在web文件夹中。怎么了?
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
}发布于 2018-03-13 22:42:36
copy { ... }块只设置从compile配置复制依赖文件,而不将项目的资源复制到web中。compileKotlin2Js任务也是如此,它只将编译好的Kotlin类放到目录中。
要复制main源集的资源,可以添加另一个copy { ... }块,如下所示:
build.doLast {
// ...
copy {
from sourceSets.main.output.resourcesDir
into "${projectDir}/web"
}
}请注意,如果您只复制这些文件,您可能会得到上次运行时留下的陈旧输出文件(如果源目录中不再存在文件,则不会将其副本从目标目录中删除)。相反,考虑使用compileKotlin2Js任务的默认输出文件位置和一个任务来同步目录,如本指南中所描述的(它没有提到资源;按照上面的建议使用from ...添加它们)。如果您需要自定义输出文件名,可以对其进行archivesBaseName。
https://stackoverflow.com/questions/49265728
复制相似问题