AngularJS application minification protection

こ雲淡風輕ζ 提交于 2021-02-11 17:57:18

问题


I am having a problem that maybe someone can guide me to solve it. I have an angularjs app that I am minifying to get a production distribution.

Like the documentation says here I can use $inject keyword to avoid Dependency injection problems.

After the minification process, I am now having the following error but since the code was minified I am unable to find out what component (service/directive/etc) I missed to protect against minification.

is there a simple way to find out the source of the problem?

Thanks in advance.


回答1:


There's no simple way to do it. However, there are more solutions to this particular problem than using the $injector service.

  • Use ngmin task before minification. It searches for all problematic occurrences and replaces them with minify-friendly code.

  • Do what ngmin does manually. That is wherever you have such declaration:

...(function ($scope, service1) {})

replace it with

(['$scope', 'service1',
    function ($scope, service1) {})

We had the same problem in our projects and we decided to go with the minify-friendly code (second solution). Though today I'd probably give ngmin at least a try - it's stable enough now.




回答2:


If you are sure that you use [ character in the same line, you can try to grep in your source files and grep -v to [ character.

Like this:

grep function $(find . -name '*.js') |grep -v -e '\['

Or you can try to generate sourcemaps to help your browser to find the real source.



来源:https://stackoverflow.com/questions/22683356/angularjs-application-minification-protection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!