and*_*max 8 gradle kotlin webpack kotlin-frontend
我一直在期待如何使用gradle创建一个kotlin-react-app(我知道使用create-kotlin-react-app CLI工具,它不使用radle)我无法获得任何来源指向我通过.我偶然发现了kotlin前端插件(它工作)和npm和webpack插件,但我无法配置它们来运行/创建一个kotlin-react-project.我不是配置webpack的专家,所以它对我来说可能更难.
我打算创建一个多平台项目(是的,在IntelliJ中打包的kotlin经验)
当我失败时,我选择采用这种方法.
有人可以指点我的方向吗?
and*_*max 10
使用kotlin前端插件时,使用gradle构建react应用程序很容易.在IntelliJ中,请按照下列步骤操作
新模块> gradle> kotlin(Javascript)> [next,next,next ... finish]
你必须配置gradle ofcourse(根据你喜欢的方式).
我配置我的如下所示: -
buildscript {
ext.kotlin_version = '1.2.41'
ext.kotlinx_html_version = "0.6.4"
ext.kotlin_frontend_version = "0.0.30"
ext.react_version = "16.4.0-pre.31-kotlin-$kotlin_version"
ext.react_dom_version = "16.4.0-pre.31-kotlin-$kotlin_version"
repositories {
mavenCentral()
maven {
url "https://dl.bintray.com/kotlin/kotlin-eap"
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-frontend-plugin:$kotlin_frontend_version"
}
}
apply plugin: 'org.jetbrains.kotlin.frontend'
apply plugin: 'kotlin2js'
sourceCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url "http://dl.bintray.com/kotlin/kotlin-dev" }
maven { url "http://dl.bintray.com/kotlinx/kotlinx" }
maven { url "http://dl.bintray.com/kotlin/kotlin-js-wrappers" }
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-html-js:$kotlinx_html_version"
compile "org.jetbrains:kotlin-react:$react_version"
compile "org.jetbrains:kotlin-react-dom:$react_dom_version"
}
kotlinFrontend {
npm {
dependency "style-loader" // production dependency
dependency "react"
dependency "react-dom"
dependency "kotlin"
dependency "@jetbrains/kotlin-extensions"
dependency "@jetbrains/kotlin-react"
}
webpackBundle {
bundleName = "main"
sourceMapEnabled = false // enable/disable source maps
contentPath = file("${projectDir}/public") // a file that represents a directory to be served by dev server)
publicPath = "/" // web prefix
host = "localhost" // dev server host
port = 8088 // dev server port
stats = "errors-only" // log level
}
}
task copyDocs(type: Copy) {
println ":md-react:copyDocs: Copying to public directory"
from("${projectDir}/build/bundle") {
include "**/*.js"
include "*.js"
}
into "${projectDir}/public/static"
println ":md-react:copyDocs: Done copying"
}
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/"))
}
})
}
from compileKotlin2Js.destinationDir
into "${projectDir}/build/classes/main"
dependsOn classes
}
//run.dependsOn copyDocs
assemble.dependsOn assembleWeb
copyDocs.dependsOn bundle
//assemble.finalizedBy(copyDocs)
compileKotlin2Js {
kotlinOptions.outputFile = "${projectDir}/build/classes/main/web.js"
kotlinOptions.moduleKind = "umd"
kotlinOptions.sourceMap = true
}
Run Code Online (Sandbox Code Playgroud)
希望这对你有所帮助.
快乐的黑客
| 归档时间: |
|
| 查看次数: |
1529 次 |
| 最近记录: |