https://kotlinlang.org logo
#javascript
Title
# javascript
p

PHondogo

11/17/2023, 6:40 AM
Hello! How to configure production distibution for JS target to aplly DCE, but keep all names from obfuscation?
a

Artem Kobzar

11/17/2023, 8:24 AM
So, there are two steps, that works on different levels: 1. Inside your build.gradle.kts you need to add the next snippet:
Copy code
tasks.withType<org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink> {
   kotlinOptions.freeCompilerArgs += "-Xir-minimized-member-names=false"
}
p

PHondogo

11/17/2023, 8:53 AM
Thanks!
a

Artem Kobzar

11/17/2023, 9:12 AM
2. If you also need to keep the same name after the webpack, you need to create a directory inside the root of your module with name
webpack.config.d
, and add the next file with any name and
.js
extension:
Copy code
config.module.optimizations?.minimizer = 
   [new TerserPlugin({ terserOptions: { mangle: false } })].concat(config.module.optimizations?.minimizer ?? [])
🙏 1
e

Edoardo Luppi

11/17/2023, 9:21 AM
@PHondogo there is also a section of the documentation for this case https://kotlinlang.org/docs/js-ir-compiler.html#minification-of-member-names-in-production
🙏 1
2 Views