在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:Kotlin/kotlin-frontend-plugin开源软件地址:https://github.com/Kotlin/kotlin-frontend-plugin开源编程语言:Kotlin 98.6%开源软件介绍:kotlin-frontend-pluginTHIS PLUGIN IS DEPRECATEDKotlin/JS plugin contains features of Gradle plugin for Kotlin frontend development The plugin provides an easy way to gather Maven and npm dependencies, pack bundles (via webpack) and test a frontend application using Karma. By default the plugin generates all required configs for webpack, karma and manages the corresponding daemons. By using Gradle continuous build, you also can get hot module replacement feature (apply code changes in browser on the fly). See corresponding section below. HowtoConfigure Gradle projectFirst of all you have to apply plugin buildscript {
ext.kotlin_version = '1.3.21'
repositories {
jcenter()
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:0.0.45"
}
}
// apply plugin
apply plugin: 'org.jetbrains.kotlin.frontend'
// apply kotlin2js
apply plugin: 'kotlin2js'
// configure kotlin compiler
compileKotlin2Js {
kotlinOptions.metaInfo = true
kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}.js"
kotlinOptions.sourceMap = true
kotlinOptions.moduleKind = 'commonjs'
kotlinOptions.main = "call"
} Setup npm dependenciesAll frontend plugin settings are applied in
webpack bundlerTo create a webpack bundle (for both packaging and running the dev server):
Complete exampleSee examples/frontend-only/build.gradle for a full example. Building and runningTo run dev server (that also will build kotlin sources):
To run tests:
To pack the bundle:
To stop running webpack and Karma daemons:
webpackwebpack configuration:
dev server log is located at config file is generated at webpack configuration customizationTo customize webpack configuration, you can apply additional scripts by placing them in the directory Sample structure:
KarmaKarma configuration:
This will generate a config file located at Note that for your tests to run correctly with webpack their module type must be defined as well:
If you would like to use a custom
Your custom config file will be copied to the build folder and renamed to karma log is located at Hot module replacementWebpack provides ability to apply code changes on the fly with no page reload (if possible). For reference see Webpack Hot Module Replacement documentation Webpack does a lot of work for you however to get it working well most likely you have to implement state save and restore functionality via webpack's API. See HMR.kt for corresponding Kotlin external declarations for webpack API and main.kt for sample save/load. Briefly at module load accept HMR feature and listen for disposal module.hot?.let { hot ->
hot.accept() // accept hot reload
hot.dispose { data -> // listen for disposal events
data.my-fields = [your application state] // put your state in the 'data' object
}
} To get previously saved state at module load use module.hot?.data?.let { data -> // if we have previous state then we are in the middle of HMR
myRestoreFunction(data) // so get state from the 'data' object
} Finally use Gradle continuous build with run task to get live replacement every time you change your code.
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论