0

My Angular 1 code works fine in development. But when I compress my Angular project to dist with Grunt, my directives run before my services and app.run(), which results in breaking the page.

I traced the issue to uglify which changes the code execution order. I don't know how to prevent my uglify from changing the execution order.

2
  • I read your answer to a below post. Why is the excution order important? Perhaps you should check if you can fix the code so it's not dependant on the order angular loads directives etc? Commented Jun 29, 2016 at 7:48
  • The directives depend on variable in a service. this service triggers in App.run() function, that is at the start of the app. Uglify pushes this function below the directive. That's the issue Commented Jun 29, 2016 at 8:31

1 Answer 1

1

Below solution worked for me. May be this will help you too. I refered it from here.

Three solutions:

  • Make the grunt task do not include unwanted files, and include those files already minified in your app.

  • If problem still occurs after first solution, your angular modules are not "uglify friendly". There's a special way to declare your dependencies so that minifying goes smooth, as described on this page ("a note on minification" paragraph) for example. Please note that instead of doing this declaration "by hand", you can use the "ng-min" task that automatize the process and keep your code clean.

  • Well, in my case I still had issue, so I ended turning off the "mangle" option in uglify (that very option that make long strings into smaller to compress response size). You can turn off the option like this :

    uglify: {
        options: {
           mangle: false
        },
    }
    
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the tip. But my issue is not because of the injection. Its the order of execution. Directives goes to top before everything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.