My website has several small JavaScript files that I currently merge into one file and then minimize using terser. The website functions perfectly with the minimized version.
Now, I want to take it a step further and obfuscate the code using JavaScript-Obfuscator (). I have set up a gulp task to generate the obfuscated version:
gulp.task('obfus', function() {
gulp.src('src/main/webapp/js/mysite.min.js')
.pipe(javascriptObfuscator({
compact: true
})).pipe(gulp.dest('src/main/webapp/js/dist'));
});
However, when I tried to run the website after obfuscation, I encountered this error:
Uncaught ReferenceError: loc is not defined
at eval (eval at exampledomain.<computed> (mysite.min.js?:1:71178), <anonymous>:1:39)
The line of code causing the error is as follows:
eval('exampledomain.build' + type + '(loc)');
I am utilizing "eval" to dynamically call different functions based on the variable "type."
How can I resolve this issue?