There are javascript obfuscators around like http://www.javascriptobfuscator.com/Default.aspx. They work on simple javascript code. But would they work on more complicated front-end AngularJS code which may have several files for controllers, services, modules?
这里有一些javascript混淆器,比如http://www.javaspple fuscator.com/default.aspx。他们使用简单的javascript代码。但是,他们会研究更复杂的前端AngularJS代码吗?
What tools do the experienced programmers on * use for obfuscating their AngularJS code? Or you don't at all because it is impossible to obfuscate front-end code?
*网站上有经验的程序员用什么工具来混淆他们的AngularJS代码?或者你根本不这么做,因为不可能混淆前端代码?
1 个解决方案
#1
18
You can use tools like Uglify or the Closure Compiler to minify and obfuscate AngularJS code, but it can get tricky because of Angular's ability to inject dependencies based on the name of the variable used (which will all be changed when you minify or obfuscate the code).
您可以使用Uglify或闭包编译器之类的工具来缩小和混淆AngularJS代码,但它可能会变得棘手,因为angle可以根据所使用的变量的名称注入依赖项(当您缩小或混淆代码时,这些变量都将被更改)。
You'll need to use the array form of defining your modules, controllers, etc. It's explained in the "Notes on Minification" section in step 5 of the Angular tutorial: https://docs.angularjs.org/tutorial/step_05
您将需要使用定义模块、控制器等的数组形式。在角度教程的第5步“关于缩小的注释”一节中解释了这一点:https://docs.angularjs.org/tutorial/step_05
Basically, if you're currently using the shorthand method of dependency injection, ie:
基本上,如果您目前使用的是依赖注入的简写方法,即:
myApp.controller('myController', function($scope, $http) { ... });
you need to change it to the more verbose array based method:
您需要将其更改为更详细的基于数组的方法:
myApp.controller('myController', ['$scope', '$http', function($scope, $http) { ... }]);
This way you're telling angular what objects to inject into your function using strings, which won't be changed during minification, instead of relying on names of the $scope and $http variables themselves.
通过这种方式,您可以使用string向函数中注入什么对象,这些对象在缩小时不会被修改,而不是依赖于$scope和$http变量本身的名称。
There is a command line tool called ngmin that will automatically make these changes for you if you don't want to modify your codebase: https://github.com/btford/ngmin
如果您不想修改代码基,那么有一个名为ngmin的命令行工具可以自动为您做这些更改:https://github.com/btford/ngmin
The 'Conceptual Overview' section of the ngmin readme also has a good explanation of this problem.
ngmin readme的“概念性概述”部分对这个问题也有很好的解释。
#1
18
You can use tools like Uglify or the Closure Compiler to minify and obfuscate AngularJS code, but it can get tricky because of Angular's ability to inject dependencies based on the name of the variable used (which will all be changed when you minify or obfuscate the code).
您可以使用Uglify或闭包编译器之类的工具来缩小和混淆AngularJS代码,但它可能会变得棘手,因为angle可以根据所使用的变量的名称注入依赖项(当您缩小或混淆代码时,这些变量都将被更改)。
You'll need to use the array form of defining your modules, controllers, etc. It's explained in the "Notes on Minification" section in step 5 of the Angular tutorial: https://docs.angularjs.org/tutorial/step_05
您将需要使用定义模块、控制器等的数组形式。在角度教程的第5步“关于缩小的注释”一节中解释了这一点:https://docs.angularjs.org/tutorial/step_05
Basically, if you're currently using the shorthand method of dependency injection, ie:
基本上,如果您目前使用的是依赖注入的简写方法,即:
myApp.controller('myController', function($scope, $http) { ... });
you need to change it to the more verbose array based method:
您需要将其更改为更详细的基于数组的方法:
myApp.controller('myController', ['$scope', '$http', function($scope, $http) { ... }]);
This way you're telling angular what objects to inject into your function using strings, which won't be changed during minification, instead of relying on names of the $scope and $http variables themselves.
通过这种方式,您可以使用string向函数中注入什么对象,这些对象在缩小时不会被修改,而不是依赖于$scope和$http变量本身的名称。
There is a command line tool called ngmin that will automatically make these changes for you if you don't want to modify your codebase: https://github.com/btford/ngmin
如果您不想修改代码基,那么有一个名为ngmin的命令行工具可以自动为您做这些更改:https://github.com/btford/ngmin
The 'Conceptual Overview' section of the ngmin readme also has a good explanation of this problem.
ngmin readme的“概念性概述”部分对这个问题也有很好的解释。