Michael
Michael

Reputation: 508

AngularJS application minification protection

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.

Upvotes: 0

Views: 361

Answers (2)

Michał Miszczyszyn
Michał Miszczyszyn

Reputation: 12701

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.

Upvotes: 3

Lajos Veres
Lajos Veres

Reputation: 13725

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.

Upvotes: 0

Related Questions