I agree with @0x23212f's answer@0x23212f's answer. Obfuscating or pre-compiling JavaScript has limited potential. If it were C you might have better success, but high-level languages, including Java, can readily be de-compiled or de-obfuscated.
With this in mind, you will have to control the server-space in which it is stored. One nice benefit to doing it this way, is that your stack traces will be intact.
I assume since you have not yet solved this problem, than it must be a new product. New products tend to have errors even in production so full stack-traces will be useful.
If you must pre-compile, you take a few steps such as
- Using Google Closure Compiler (which will likely give you a mapping to the original for stack trace purposes) This is a reliable way to obfuscate variable names, but the structure of the program remains intact.
- Distributing the file as an encrypted Base64 string with some sort of decryption method. (easily circumvented)
- Some type of self-inspection to alert you if the files are changed (requires internet access)