MrPowerGamerBR
10/25/2025, 8:21 PMturansky
10/25/2025, 9:19 PMtarget="es2015"
2. Inline anonymous functions
3. Granularity - whole-program (if app is solid) or per-file if you use lazy modules
4. Disable redundant polyfills
More options - here
1. Vite bundler (instead of Webpack)
a. (depends on your case)MrPowerGamerBR
10/26/2025, 2:33 AMkotlin.js.ir.output.granularity=insertgranularityhere to my gradle.properties ) but no matter which granularity I choose the bundle size doesn't change at all, even if I try clearing the cache with ./gradlew cache it doesn't change anything
The options that you provided in Gradle did work however kodee loving (I was already using es2015)
I did try the vite compiler (this one by @CLOVIS https://vite-kotlin.opensavvy.dev/guides/index.html) but sadly I don't know why it doesn't work for me (the plugin says that it doesn't have permission to create the node_module and, when the folder is manually created, then vite complains that it can't find a module
* What went wrong:
Execution failed for task ':viteCompileKotlinProd'.
> java.nio.file.FileSystemException: L:\KotlinJSBundleSizeTests\build\vite\prod\node_modules: O cliente n├úo tem o privil├®gio necess├írio
PS L:\KotlinJSBundleSizeTests> ./gradlew viteBuild
> Task :viteBuild FAILED
failed to load config from L:\KotlinJSBundleSizeTests\build\vite\prod\vite.config.mjs
error during build:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'vite-plugin-commonjs' imported from L:\KotlinJSBundleSizeTests\build\vite\prod\node_modules\.vite-temp\vite.config.mjs.timestamp-1761445363010-e1952b5fcb28b.mjs
at packageResolve (node:internal/modules/esm/resolve:845:9)
at moduleResolve (node:internal/modules/esm/resolve:918:18)
at defaultResolve (node:internal/modules/esm/resolve:1148:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:528:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:497:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:231:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:97:39)
at link (node:internal/modules/esm/module_job:96:36)
[Incubating] Problems report is available at: file:///L:/KotlinJSBundleSizeTests/build/reports/problems/problems-report.html
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':viteBuild'.
> Process 'command 'L:\.gradle\nodejs\node-v22.0.0-win-x64\node.exe'' finished with non-zero exit value 1
What I'm trying to do right now is replacing some dependencies with some "lightweighter" alternatives (example: Ktor -> native fetch with suspend) however some are harder to replace (Compose's HTML runtime is big, ouch!)
Currently the bundle is ~1MB, 275KBs gzipped
One thing that I noticed that can decrease the bundle size is surprise, updating Kotlin version. Currently I'm using Kotlin 2.2.0 however I did try a difference between Kotlin 2.2.0 and Kotlin 2.2.21 and Kotlin 2.2.21 created bundles that were 200KBs smaller (but I haven't updated my project to 2.2.21 yet)jw
10/26/2025, 4:05 AMturansky
10/26/2025, 11:52 AMMrPowerGamerBR
10/26/2025, 3:14 PM• Don't use coroutines
• Don't use serialization
• Don't use collectionsat this point it is better to not use Kotlin /j
jw
10/26/2025, 3:16 PMjw
10/26/2025, 3:17 PMMrPowerGamerBR
10/26/2025, 3:18 PMMrPowerGamerBR
10/26/2025, 3:19 PMMrPowerGamerBR
10/26/2025, 3:19 PMMrPowerGamerBR
10/26/2025, 3:59 PMio.github.turansky.kfc.application plugin I got a larger bundle size than without it
With the plugin: 819 KB
Without the plugin: 743 KB
(The project is very simple, meant only to test how much each dependency was taking up in the final bundle, so the code is a bit nonsensical: https://gist.github.com/MrPowerGamerBR/eae9c8f74e771c090e1eb91beafcb500)turansky
10/26/2025, 7:27 PMper-file for lazy modules.
But whole-program required in your case for less bundle.turansky
10/26/2025, 7:30 PMkotlin-stdlibCLOVIS
10/27/2025, 8:19 AMI did try the vite compiler (this one by @CLOVIS https://vite-kotlin.opensavvy.dev/guides/index.html) but sadly I don't know why it doesn't work for me (the plugin says that it doesn't have permission to create theWhat OS are you on? I've heard of people having that issue on Windows but I haven't been able to fix itand, when the folder is manually created, then vite complains that it can't find a modulenode_module
MrPowerGamerBR
10/27/2025, 6:17 PMCLOVIS
10/27/2025, 6:57 PMMrPowerGamerBR
10/28/2025, 2:37 AM