For those struggling with slow Kotlin/JS build tim...
# javascript
h
For those struggling with slow Kotlin/JS build times. 1. Switch to esbuild for Faster Compile Speeds Kotlin/JS uses Webpack for bundling by default, but you can significantly improve compile speed by switching to
esbuild
. ◦ Create a folder named
webpack.config.d
in the module root. ◦ Inside the folder, add a
config.js
file to configure
esbuild-loader
. ◦ Example configuration: https://gist.github.com/hikaMaeng/2b38fb3d0bb23e0d9dbccc2f4168af28 ◦ Use
npm install -g
instead of
implement-npm
, as
implement-npm
slows down the process during each compilation ◦ npm install --save-dev -g esbuild esbuild-loader 2. Optimize Gradle Tasks for Faster Builds Certain Gradle tasks can be skipped after the initial build to reduce build time. ◦ Insert the following snippet into your project's
build.gradle.kts
file. ◦ Comment it out during the first build. ◦ After the first successful build, uncomment it to enable faster subsequent builds.
Copy code
tasks.withType<RootPackageJsonTask>().configureEach {this.enabled = false}
tasks.withType<KotlinNpmInstallTask>().configureEach {this.enabled = false}
tasks.withType<NodeJsSetupTask>().configureEach {this.enabled = false}
tasks.withType<YarnLockCopyTask>().configureEach {this.enabled = false}
tasks.withType<YarnSetupTask>().configureEach {this.enabled = false}
tasks.withType<YarnLockStoreTask>().configureEach {this.enabled = false}
3. Move more code into JavaScript and use it as an external resource.
o
Nice! I'll try this out. Where should I place the webpack.config.d folder? in the build folder?
h
projectRoot --+jsmoduleRoot -----+src -----+webpack.config.d --------config.js
o
Perfect 🙂
It does not seem to pick up the config file. Our use case is to create a library if makes any difference?
h
yes
create it
o
I have created it but it seems not to be picked up? This is my conclusion from a very scientific approach by only having a
throw exception
in the config.js file in the webpack.config.d folder.