https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
javascript
  • c

    caffeine

    11/19/2022, 3:24 AM
    logs.txt
  • p

    Piotr Krzemiński

    11/22/2022, 2:55 PM
    I have two multiplatform projects, one is
    :rest:model
    and the other one
    :domain:model
    I depend on both in a certain third Kotlin/JS project, and getting an error
    duplicate target file will be created
    from
    processDceKotlinJs
    . One of the solutions seems to be setting different names for JS bundles (like
    rest-model
    and
    domain-model
    ). How can I customize the bundle names? I’m looking around Gradle DSL
    kotlin { js { … } }
    but so far didn’t find it
    t
    • 2
    • 3
  • s

    Shubham Singh

    11/26/2022, 7:23 AM
    Hi everyone I'm a newbie to Kotlin/JS and want to know if there's any solution that you guys use for integrating Firebase into your web apps?
    a
    • 2
    • 3
  • r

    Robert Jaros

    11/27/2022, 9:00 AM
    An app compiled with Kotlin/JS 1.8.0-Beta runs ~7% slower than with Kotlin 1.7.21. It's not much, but it's noticeable in my benchmark. Should this be expected and why?
    j
    • 2
    • 3
  • d

    Dirk

    11/28/2022, 12:07 PM
    I use import.meta.env.DEV to check whether I am doing a build for development or production and configure my logger accordingly. However, I would now also like to store parameters for different systems independently of the build method (dev/prod). Can I pass a profile when building and access it with import.meta.env in the browser js client?
  • s

    spierce7

    11/28/2022, 10:08 PM
    When is generate externals going to get some love? It was promised like 4 or 5 years ago, and I haven't been able to get it working with a compilable application even once.
    e
    • 2
    • 3
  • b

    Big Chungus

    11/29/2022, 3:15 PM
    Has anyone got this error when trying to open kjs IR sourcemaps in the browser?
    Could not load content for <webpack://sandbox/util.kt> (Fetch through target failed: Unsupported URL scheme; Fallback: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME)
    r
    n
    e
    • 4
    • 16
  • m

    Mark Vogel

    11/29/2022, 5:47 PM
    I'm attempting to build a React app in KotlinJS and JS alongside one another. This is related to a similar question someone asked before in this thread and linked to this StackOverflow question. I'm able to make the dependency work as stated in that post, but unfortunately, React has custom DSL and requires compiling with
    npm run-script build
    (i.e.
    react-scripts build
    ). Does anyone know a way for Gradle to compile the React JavaScript code in my JS module and then use that compiled code as the dependency to include and interop?
    t
    s
    • 3
    • 6
  • e

    eygraber

    11/30/2022, 8:58 AM
    Anyone ever get stuck on
    92% sealing asset processing TerserPlugin
    when running
    browserProductionWebpack
    ? I'm hoping the issue is that it just takes a long time to run, and if so, is there any way to speed it up (give it more RAM, etc...)?
  • s

    spierce7

    11/30/2022, 4:55 PM
    if I've got a nodejs kotlin-js application, what is the expected way for me to package and ship the application? Do I just copy everything in the
    <root project>/build/js
    folder, and then manually run the js file in the
    packages/<app name>/kotlin/<app name>.js
    ? I'm curious if there is a nicer way to package everything up.
  • m

    Mike Dawson

    11/30/2022, 7:10 PM
    Has anyone ever used generic types with react components? e.g. external interface MySelectListProps<T>: Props { var options: List<T> var onSelected: (T) -> Unit, } Is there any established pattern, or is this a bad idea?
    t
    • 2
    • 1
  • s

    Slackbot

    12/01/2022, 3:20 AM
    This message was deleted.
  • k

    Konyaco

    12/01/2022, 4:06 AM
    Hello, has anyone tried to use [Rust-Tauri](https://tauri.app/) with kotlin/js and compose-wasm? I am trying to import tauri library:
    implementation(npm("@tauri-apps/api", "1.2.0", true))
    But I got lots of compilation error in
    lib.dom.kt
    (Prcture 1), which is converted from
    tsstdlib
    ts library. I think we just need the
    invoke()
    function defined in tauri (Picture 2), so I tried to set
    generateExternals
    to
    false
    and manually add external definition in my
    Main.kt
    , then the Tauri console tells me "cannot found xxx function." What is the recommended way to use tauri in k/js?
  • s

    Shubham Singh

    12/01/2022, 5:17 PM
    Hello everyone Greetings of the day I need some help with figuring out how to get the
    BrowserRouter
    working on my codebase. So I have created a new Kotlin/JS app and the only change I have made in the code is instead of directly rendering the
    welcome
    screen, I am loading it inside a
    BrowserRouter
    Like this:
    createRoot(container).render(
        BrowserRouter.create {
            Routes {
                Route {
                    path = "/login"
                    element = welcome
                }
                Route {
                     path = "*"
                    element = VFC { +"404 Not found!" }.create()
                }
            }
        }
    )
    Now, the problem with the output of this code is that if I type
    <http://localhost:8080/login>
    in my browser, it gives me the following error:
    Cannot GET /login
    . Following are the only two entries I see in the console:
    1. failed to load resource: the server responded with a status of 404 (Not Found)
    
    2. DevTools failed to load source map: Could not load content for <chrome-extension://fjdmkanbdloodhegphphhklnjfngoffa/lib/browser-polyfill.min.js.map>: System error: net::ERR_BLOCKED_BY_CLIENT
    Now the interesting thing is that, instead of a
    BrowserRouter
    , if I use a
    HashRouter
    and instead of entering
    <http://localhost:8080/login>
    , I enter
    <http://localhost:8080/#/login>
    in my browser, the same code starts working perfectly fine 👍 So I am not sure what changes do I need to make in order for the
    BrowserRouter
    to work fine. Any help would be greatly appreciated.
    m
    t
    • 3
    • 21
  • r

    Racka N

    12/01/2022, 8:09 PM
    Anyone knows what the issue might be here. I opened this project after a while, updated to Kotlin 1.7.20 and switched to using the
    kotlin-wrappers
    BOM then added the MUI showcase sample. Now it compiles (using
    :browserDevelopmentRun
    ) and opens on the correct localhost but it's blank. Nothing is showing up on the browser. It used to work perfectly in the past. Project: https://github.com/racka98/Kotlin-JS-Glass-UI
    a
    • 2
    • 2
  • p

    Prabin Timsina

    12/02/2022, 4:29 PM
    Is there a guide on how to use modal component from react-bootstrap in KotlinJs? I think I found a closer answer on stackoverflow but not sure how to add dependency to `react-bootstrap`module. I did
    npm install react-bootstrap bootstrap
    and the module is installed in
    build/js/node_modules/bootstrap
    .
    h
    • 2
    • 4
  • p

    Prabin Timsina

    12/03/2022, 4:29 PM
    Why does my browser auto refreshes twice to show changes made in code? First refresh does not show the changes, only second one does. There are some warnings in console (see attached imaged) most likely related to webpack. I am running
    jsBrowserDevelopmentRun --continuous
    . (I also have ktor server running alongside)
    build.gradle
    plugins {
        id 'org.jetbrains.kotlin.multiplatform' version '1.7.21'
        id 'application'
        id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.21'
    }
    
    def ktorVersion = "2.1.3"
    
    group = 'me.developer'
    version = '1.0-SNAPSHOT'
    
    repositories {
        jcenter()
        mavenCentral()
        maven { url '<https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven>' }
    }
    
    kotlin {
        jvm {
            compilations.all {
                kotlinOptions.jvmTarget = '1.8'
            }
            withJava()
            testRuns["test"].executionTask.configure {
                useJUnitPlatform()
            }
        }
        js() {
            binaries.executable()
            browser {
                commonWebpackConfig {
                    cssSupport.enabled = true
                    devServer?.port = 8080
                }
            }
        }
       // dependencies {...}
    }
    
    application {
        mainClassName = 'me.developer.application.ServerKt'
        applicationDefaultJvmArgs = ["-Dio.ktor.development=true"]
    }
    
    tasks.named('jvmProcessResources') {
        def jsBrowserDistribution = tasks.named('jsBrowserDistribution')
        from(jsBrowserDistribution)
    }
    
    tasks.named('run') {
        dependsOn(tasks.named('jvmJar'))
        classpath(tasks.named('jvmJar'))
    }
    l
    r
    m
    • 4
    • 5
  • e

    Eugene Maksymenko

    12/04/2022, 11:50 PM
    Huge update of WorldWindKotlin KMP 3D map engine with a lot of bugfixes released! https://github.com/WorldWindEarth/WorldWindKotlin/releases/tag/v1.1.3
  • l

    Luca

    12/05/2022, 5:01 AM
    Hi, does anyone know why launching many concurrent operations/api calls with coroutines would be 3x-4x slower in firefox vs chrome? something along the lines of this:
    coroutineScope {
        storeListItems.forEachIndexed { i, item ->
            launch(Dispatchers.Default) {
                val price = api.getPurchasePrice(item.id)
                storeListItems[i] = StoreListItem(item, price)
                stateManager.updateScreen(StoreListState::class) {
                    it.copy(
                        storeListItems = storeListItems,
                    )
                }
            }
        }
    }
    where I have to fetch the prices of many store items with a separate api call for each store item by their id. Additionally, chrome will update the screen as I expect (the order in which the prices get updated happens progressively) while firefox doesn’t seem to be handling the concurrency correctly and it updates the screen all at once)
    s
    • 2
    • 3
  • m

    Mark Vogel

    12/06/2022, 4:47 PM
    How can I link to a Kotlin dependency in HTML? For example, I'd like to convert this:
    <link rel="stylesheet" href="<https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css>">
    <link rel="stylesheet" href="path/to/bootstrap/dependency/dist/css/bootstrap.min.css"> <!-- to something like this -->
    I just can't seem to figure out the correct path to point to the Gradle/NPM dependency; hopefully it's possible haha Appreciate the help!
    h
    • 2
    • 5
  • e

    eygraber

    12/07/2022, 1:19 AM
    I ran into an issue in Compose for Desktop where a function isn't implemented in the js source set:
    internal actual fun ByteArray.putBytesInto(array: IntArray, offset: Int, length: Int): Unit =
       TODO("implement js ByteArray.putBytesInto()")
    The jvm implementation is:
    internal actual fun ByteArray.putBytesInto(array: IntArray, offset: Int, length: Int) {
        ByteBuffer.wrap(this)
            .order(ByteOrder.LITTLE_ENDIAN) // to return ARGB
            .asIntBuffer()
            .get(array, offset, length)
    }
    Would the following be a correct implementation (even if not optimal):
    internal actual fun ByteArray.putBytesInto(array: IntArray, offset: Int, length: Int) {
      val byteBuffer = Uint8Array(this.toTypedArray()).buffer
      val intArray = Int32Array(byteBuffer, offset, length)
      for(i in 0 until intArray.length) {
        array[i] = intArray[i]
      }
    }
    t
    • 2
    • 2
  • p

    Prabin Timsina

    12/07/2022, 4:07 AM
    How do I create a react component using kotlin? example.js
    const Input = () => {
      return <input placeholder="Your input here" />;
    };
    1. My attempt which does not render anything when method is called:
    fun input(): ReactElement<Props>? {
        return createElement {
            ReactHTML.input {
                this.attrs.placeholder = "Your input here"
            }
        }
    }
    2. Also tried this github example but no success: https://github.com/Kotlin/react-redux-js-ir-todo-list-sample/blob/master/src/main/kotlin/reactredux/components/Link.kt#L12
    t
    b
    • 3
    • 2
  • s

    spierce7

    12/07/2022, 3:57 PM
    Has anyone else seen this? Either this is a huge bug, no one is using dynamic except me, or there is some limitation around dynamic that I'm not aware of. Any time I use dynamic, I need to ensure it's done on it's own line, otherwise the code doesn't run properly. https://youtrack.jetbrains.com/issue/KT-55182/Incorrect-Compilation-for-suspend-function-that-returns-dynamic
    e
    • 2
    • 1
  • l

    louiscad

    12/09/2022, 12:30 AM
    Hello, I'm looking for good examples of websites and webapps made with Kotlin/JS to show off. I'd mention some of them in my talk "Why we ditched JavaScript for Kotlin/JS" that I'll be giving later today for the 2nd time. Please, if you know good ones, drop the link of the website (plus public repo if open source) in the thread 👇🏼
    n
    b
    +2
    • 5
    • 5
  • g

    Gordon

    12/10/2022, 9:00 PM
    Any example of using kotlin/js library in existing js project?
    b
    • 2
    • 4
  • w

    WukongRework.exe

    12/12/2022, 12:05 AM
    hello, I was doing some testing with JS codegen and found something interesting. For example if we have an expression
    foo?.bar?.baz
    the code generated is
    (tmp$ = foo != null ? foo.bar : null) != null ? tmp$.baz : null
    . This feels unnecessary as there are multiple
    null
    checks. Couldnt an alternative be
    foo == null ? null : (foo.bar == null ? null : foo.bar.baz)
    ? this removes all the extra
    != null
    checks. If there is some reason for this that I am unaware, please let me know. Thanks in advance for the clarification
    e
    a
    • 3
    • 8
  • d

    Dmitriy Malayev

    12/12/2022, 5:00 PM
    https://kotlinlang.slack.com/archives/C5ZTZ6ER0/p1670862893270809
  • s

    spierce7

    12/17/2022, 3:35 PM
    https://github.com/Kotlin/kotlinx-nodejs is dead, in favor of https://github.com/JetBrains/kotlin-wrappers/blob/master/kotlin-node/README.md right? Why not mark the repository as deprecated so that people don't waste time trying to pull it from jcenter (which no longer seems to work).
    t
    v
    • 3
    • 7
  • a

    andylamax

    12/17/2022, 4:49 PM
    With the emerging of other Javascript runtimes (i.e. Deno & Bun), whats the future of running kotlin/js there?? Do we also use the
    nodejs
    target?? if so, won't the name be confusing?? Whats the plan of supporting this??
    g
    • 2
    • 5
  • s

    spierce7

    12/17/2022, 10:30 PM
    What's the best way to package a node-js server in a docker container? I'm doing the following: 1. Run a full project clean 2. Build only the server I want to package 3. Grabbing the
    <root project>/build/js
    dir and putting it in the docker container. The problem is that this folder contains EVERY single library that any project in my entire workspace touches. So my docker image is 400 MB, when it only needs to be 20 or 30 MB. Is there any way to JUST package exactly the used dependencies?
    t
    g
    • 3
    • 29
Powered by Linen
Title
s

spierce7

12/17/2022, 10:30 PM
What's the best way to package a node-js server in a docker container? I'm doing the following: 1. Run a full project clean 2. Build only the server I want to package 3. Grabbing the
<root project>/build/js
dir and putting it in the docker container. The problem is that this folder contains EVERY single library that any project in my entire workspace touches. So my docker image is 400 MB, when it only needs to be 20 or 30 MB. Is there any way to JUST package exactly the used dependencies?
t

turansky

12/17/2022, 10:51 PM
Build only the server I want to package
On this step you will install all NPM dependencies of your project
s

spierce7

12/17/2022, 10:58 PM
yes. I suppose there is no reasonable way around that?
t

turansky

12/17/2022, 11:03 PM
Simplest solution, which I see: 1. Build app 2. Copy resulted
js
file and
package.json
(in IR resulted file can be single) in separate folder 3. Run
npm i
4. Pack folder in docker container
Step 3 can be skipped, if you can bundle dependencies inside resulted
js
file
s

spierce7

12/17/2022, 11:05 PM
I'd have to also move over any of the project dependency folders as well
Now that i think about this though... I should be able to make a gradle task that can detect those and move them over...
Yes - I do have to get the project dependency folders as well... Even though the IR compiler has the js files there locally, the NPM dependencies they references aren't there.
t

turansky

12/17/2022, 11:13 PM
Even though the IR compiler has the js files there locally
It will be safety to build single JS file
s

spierce7

12/17/2022, 11:19 PM
how do I do this?
The browser can do this with webpack, but how would I do this using a nodejs target?
@turansky ?
t

turansky

12/18/2022, 5:20 PM
The browser can do this with webpack, but how would I do this using a nodejs target?
The same way 🙂
s

spierce7

12/18/2022, 5:21 PM
Webpack is automatically applied to browser in kotlin. Is there a way for me to turn it on for nodejs?
t

turansky

12/18/2022, 5:21 PM
kotlin.js.ir.output.granularity=whole-program
to build single JS file
Webpack is automatically applied to browser in kotlin. Is there a way for me to turn it on for nodejs?
browser
target for Kotlin/JS (to activate distribution) + node configuration for webpack (for valid
globalThis
)
s

spierce7

12/18/2022, 5:25 PM
kotlin.js.ir.output.granularity=whole-program
It looks like the file this creates doesn't contain the
node_modules
dependencies.
browser
target for Kotlin/JS (to activate distribution) + node configuration for webpack (for valid
globalThis
) (edited)
I don't follow what you mean here
t

turansky

12/18/2022, 5:26 PM
It looks like the file this creates doesn’t contain the
node_modules
dependencies.
Yes, it’s classic NodeJS distribution mode
I don’t follow what you mean here
kotlin.js {
    browser {
        commonWebpackConfig {
            globalThis = "globals" // for node
        }
    }
}
s

spierce7

12/18/2022, 5:29 PM
ok - I see what you mean
I ended up creating a gradle plugin that traverses across all of a projects project dependencies grabbing the npm dependencies, and then recreates a slim version that can be easily deployed
g

gildor

12/19/2022, 7:41 AM
Wouldn’t be better to use minimized resulting js after all obfuscation/tree shaking with all dependencies bundled? it sounds a bit more efficient to pack in docker
t

turansky

12/19/2022, 2:30 PM
Both options can be useful. Bonus of external dependencies - dependencies refresh, without rebuild
And faster build 🙂
s

spierce7

12/19/2022, 2:34 PM
Well - the other thing, if you are using a function or serverless platform to run your code, which I am, supposedly the startup time is much worse for a single file, than lazily with many small files.
g

gildor

12/21/2022, 2:44 AM
Good point 👍 I really curious is it possible (for example with webpack) to have tree-shaking and obfuscation on dependency js file and still have lazy initialisation
s

spierce7

12/21/2022, 6:12 PM
The problem with cold start times is that even though things is less the code actually initializing during it's running phase, it's that it has to 1. 100% of your application has to be loaded from disk. The size of your app becomes a limiting factor and 2. All that js code has to be interpreted, even if it's not run (I think?).
in an ideal world with a JS server, I would only create endpoints / routes during initialization. Any dependencies beyond express, I would
require
inside of the endpoint call and then use. This would yield the best times. Currently this isn't reasonably possible with kotlin js unless you separate your code into an http module and a separate module for actually doing the logic of the endpoints. Even then, I'm not certain how it will work
g

gildor

12/22/2022, 5:49 AM
Yes, I see, it’s an issue of deferred module initialization, which is not really work with Kotlin out of the box I feel that app size by itself shouldn’t be a huge issue by itself, but interpretation and overall init looks like a bigger problem. After all app size limited mostly by disk speed, everything else is runtime init speed. But in this case why there is any difference in case of Kotlin app when you have single file and your app file + dependencies in separate files if program anyway init on start
supposedly the startup time is much worse for a single file, than lazily with many small files.
Really curious how different it is without on demand modules loading
View count: 30