Hello everyone, is there a way to exclude ktor dep...
# javascript
m
Hello everyone, is there a way to exclude ktor dependency from generated .js file? It adds too much size to the generated javascript file even though ktor is not used in @JSExport files. I also tried this but it didn’t make any difference.
c
The only possible way not to have Ktor in your JS, is to not use Ktor.
m
so I guess entire Kotlin stdlib gets compiled no matter if I’m exposing ktor classes to javascript or not? Thanks for the answer
c
Ktor is not part of the standard library. Everything you use must be in the file, no matter if you expose it or not.
👍 1
a
Also, you could try to compile into ES-modules and there is a possibility that the TreeShaking will cut more parts.
c
I think it's the opposite, compiling into smaller files will make tree shaking harder than compiling into a single massive file.
but it should probably be measured
a
I mean, not compilation into small files (file-to-file), but to change the module system from commonjs to esm, you will still have the per-module compilation but with the different js module system.
m
It is slightly smaller, but when built with this script it still grows to 500 kb:
Copy code
#!/bin/bash
PACKAGE_ROOT=packages/js-package
echo "> Copy shared.js"
cp shared/build/distributions/shared.js $PACKAGE_ROOT/src
echo "> Copy types"
cp shared/build/compileSync/main/productionExecutable/kotlin/*-shared.d.ts $PACKAGE_ROOT/src/shared.d.ts
cd $PACKAGE_ROOT
echo "> Install dependencies"
npm install
echo "> Build"
npm run build
sorry for stupid questions. I do Android and iOS. quite new to web with multiplatform.
a
Try to add the next code to your build.gradle.kts:
Copy code
kotlin {
    js(IR) {
        useEsModules() // <- This one
        // End if you have the next line
        useCommonJs() // <- remove it
    }
}
m
same result. btw do you use generated .js file directly from /build directory or you modify it somehow?
a
I think it's the opposite, compiling into smaller files will make tree shaking harder than compiling into a single massive file.
This is not entirely true. Tree shaking output is not impacted wether its a single large file, or many small files as long as the file(s) are ESX module(s) respectively, The number of files might impact speed during shaking but no the output size