Writing javascript applications with Kotlin

前端 未结 3 520
时光取名叫无心
时光取名叫无心 2021-02-05 07:31

I recently started to have a look at Kotlin and managed to create my first JVM applications. It\'s so cool to have a single language that compiles both to Java and JS. So, now I

3条回答
  •  無奈伤痛
    2021-02-05 07:58

    Using the pom below:

    
    
    
        4.0.0
    
        com.example.kotlin
        kotlin-js
        1.0-SNAPSHOT
        pom    
        
            1.3.61
            UTF-8
    
            1.3
            1.3
    
        
    
        
            
                org.jetbrains.kotlin
                kotlin-stdlib-js
                ${kotlin.version}
            
        
    
        
            
                
                    kotlin-maven-plugin
                    org.jetbrains.kotlin
                    ${kotlin.version}
                    
                    
                        
                                compile
                                compile
                                
                                    js
                                                        
                                
                                    
                                      ${project.basedir}/src/main/kotlin
                                    
                                    umd
                                
                        
                    
                                                    
                    
        
    
    

    Inside src/main/kotlin you can add Hello.kt containing a fun main(args : Array){println("hello")}

    then the following would print hello

    mvn clean package
    cd target
    npm i kotlin
    node js/kotlin-js.js
    

    or you can add a non-main method and then use require() from other js code or add it to the browser using

提交回复
热议问题