Piotr Bartkowiak
01/20/2025, 12:38 PMbuild/dist/ js-generated
files to have obfuscated values for debug version. I tried creating webpack.config.js file in my build.gradle file:
js(IR) {
moduleName = project.name
browser {
testTask { useKarma { useChromeHeadless() } }
webpackTask {
sourceMaps = false
mainOutputFileName.set("${project.name}.js")
output.library = project.name
doLast {
writeWebpackConfig(
project = project,
buildDirectory = buildDirectory
)
}
}
}
}
and:
private fun writeWebpackConfig(
project: Project,
buildDirectory: DirectoryProperty
) {
val webpackConfigFile = File("$buildDirectory/webpack.config.js")
val absoluteDistPath = buildDirectory.get().asFile.absolutePath
webpackConfigFile.writeText(
"""
const path = require('path');
const WebpackObfuscator = require('webpack-obfuscator');
module.exports = {
entry: ${absoluteDistPath}/build/dist/js/productionLibrary/${project.name}.js',
output: {
filename: '${project.name}.release.js',
path: path.resolve(__dirname, 'dist'),
library: '${project.name}',
},
plugins: [
new WebpackObfuscator({
rotateStringArray: true,
stringArray: true,
stringArrayEncoding: 'rc4',
debugProtection: "true",
debugProtectionInterval: true",
})
]
};
""".trimIndent()
)
}
but I don't see the webpack.config.js
file being created and obfuscation doesn't work. Any advices?Artem Kobzar
01/20/2025, 4:46 PMwebpack.config.d
in the root of your project, and add inside a file with the following content:
// file obfuscator.js
const path = require('path');
const WebpackObfuscator = require('webpack-obfuscator');
config.plugins.push(new WebpackObfuscator({
rotateStringArray: true,
stringArray: true,
stringArrayEncoding: 'rc4',
debugProtection: "true",
debugProtectionInterval: true",
}));
Piotr Bartkowiak
01/21/2025, 7:34 AMbinaries.library
for my js (because I'm building SDK). I see down there that it works only for binaries.executable
?Artem Kobzar
01/21/2025, 10:32 AMbinaries.library
?Piotr Bartkowiak
01/21/2025, 11:11 AMbinaries.library
I need to do it somehow after build, manually (or with some script): obfuscate already generated .js files after processing.
I think that webpack processing is not working with library but you can confirm