我使用IntelliJ 2022.3.3向导创建了新的Kotlin Full-Stack应用程序. 除了将Gradle设置为版本8.0.2并添加slf4j依赖项外,到目前为止我没有做任何更改,Demo Server和前端如期启动.
然后我想要更改前端端口,以及其他一些东西,但我想保持简单.
所以我添加了一个webpack.config.d
文件夹和一个webpack.config.js
文件夹.
无论我运行什么Gradle任务,更改都不会反映在webpack.config.evaluated.js
中,因此也不会apply.
WebPack.config.js:
module.exports = {
mode: 'development',
devServer: {
port: 8088,
},
};
Build.gradle.kts:
plugins {
kotlin("multiplatform") version "1.8.10"
application
}
group = "de.splitframe"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
}
kotlin {
jvm("backend") {
jvmToolchain(16)
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
js("frontend", IR) {
binaries.executable()
browser {
commonWebpackConfig {
cssSupport {
enabled.set(true)
}
}
}
}
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val backendMain by getting {
dependencies {
implementation("io.ktor:ktor-server-netty:2.0.2")
implementation("io.ktor:ktor-server-html-builder-jvm:2.0.2")
implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2")
implementation("org.slf4j:slf4j-api:2.0.6")
implementation("org.slf4j:slf4j-simple:2.0.6")
implementation("ch.qos.logback:logback-core:1.4.5")
}
}
val backendTest by getting
val frontendMain by getting {
dependencies {
implementation("org.jetbrains.kotlin-wrappers:kotlin-react:18.2.0-pre.346")
implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom:18.2.0-pre.346")
implementation("org.jetbrains.kotlin-wrappers:kotlin-emotion:11.9.3-pre.346")
implementation("org.jetbrains.kotlin-wrappers:kotlin-react-router-dom:6.3.0-pre.346")
}
}
val frontendTest by getting
}
}
application {
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=true")
mainClass.set("de.splitframe.application.ServerKt")
}
tasks.named<Copy>("backendProcessResources") {
val frontendBrowserDistribution = tasks.named("frontendBrowserDistribution")
from(frontendBrowserDistribution)
}
tasks.named<JavaExec>("run") {
dependsOn(tasks.named<Jar>("backendJar"))
classpath(tasks.named<Jar>("backendJar"))
}
现在的 struct 是:
Edit: I noticed that my settings are exported to the build though:
解决方案:
多亏了@Benjamin-Charais,我找到了问题所在.除了webpack.config.d
文件夹的位置必须与src
文件夹在同一级别外,我遵循的文档(https://webpack.js.org/guides/development/)也不适合这里.应用我的设置的正确方法是:
;(function(config) {
config.mode = 'development'
config.devServer = {
port: 8088
}
})(config);