From 15422568dc4e8d9622fefffdc35bbef1f40cae57 Mon Sep 17 00:00:00 2001 From: Ivan “CLOVIS” Canet Date: Sat, 23 Aug 2025 16:44:55 +0000 Subject: [PATCH] feat(example-simple): Support building with ESM --- vite-kotlin/README.md | 23 +++++++++++++++++++++++ examples/simple/build.gradle.kts | 1 + examples/simple/src/jsMain/resources/index.html | 2 +- 3 file(s) changed, 25 insertion(s)(+), 1 deletion(s)(-) diff --git a/vite-kotlin/README.md b/vite-kotlin/README.md --- a/vite-kotlin/README.md +++ b/vite-kotlin/README.md @@ -40,6 +40,29 @@ To configure the plugin, see [the vite block][opensavvy.gradle.vite.base.config.ViteConfig]. +### ESM + +ESM is a more modern module system natively supported by Vite. Using it may make the build faster, especially during development. + +To use ESM, you must add `useEsModules()` in the `js {}` block: +```kotlin +// … + +kotlin { + js(IR) { + browser() + binaries.executable() + useEsModules() + } +} +``` + +Additionally, you must edit your `index.html` file to use the extension `.mjs` instead of `.js`. +For example: +```html + + -- tangled.sh