3

I'm trying to deploy a meanjs project but can't seem to figure out how to minify,concat&uglify the project using grunt.

What I've found out so far :

  1. Need to run concat -> ngAnnotate -> uglify (else code won't run)
  2. need to concat in dependency order (else it won't run)

With this logic I've managed to create a single 'uglified' version of the relevant 3rd party libraries (node modules), but I'm unable to do the same for the modules I've written.

I've tried using concat tools that are supposed to reorder the files according to dependencies (grunt-concat-in-order, grunt-concat-dependencies, grunt-concat-deps) but nothing helped. Just errors of missing modules/declarations.

I've tried reordering the js files that should be concatenated, and each time something else is missing and the site loads partially (at best). reordering the files according to the order they appear in the compiled header doesn't help.

Is there something that concats Angular files according to their dependencies or or a general logic in which I should reorder them?

Thanks.

Debug Diva
  • 26,058
  • 13
  • 70
  • 123
Daniel
  • 131
  • 1
  • 1
  • 7

2 Answers2

1

FOUND IT! apparently JS and Angular are flexible with missing ';' in the end of module/directive declarations. I've went through the entire code and added missing ';' in the appropriate places.

For example:

angular.module('core').filter('xyz', [function() {
    .....
}])

Finally can go to sleep.

*original post: Angular module().factory() is not a function after concat (gulp) (cheers to Max Yari)

Community
  • 1
  • 1
Daniel
  • 131
  • 1
  • 1
  • 7
0

The first thing to check is that you actually use the DI pattern everywhere in your code as the function parameters will be replaced during uglification and thus won't be resolved let anymore.

ControllerName.$inject = ['component'] 

Or

angular.module('module') 
   .controller(['module', function (module) { /*... */}) ;

When you've done that, check if you may explicitly specify file order like this (pseudo code):

['module1_decl_file.js','module2_decl_file.js', '*.js','**/*.js']

simme
  • 1,514
  • 12
  • 23
  • Thanks for the input, By 'explicitly specify file order' do you mean the order in which the files are concatenated? I presumed the concat function adds the files in the order I've written. – Daniel Nov 16 '16 at 17:00
  • It should, yes. I haven't tried exactly the library you use but gulp-concat and similar. Have you tried concatenate it without uplifting just to verify the order? It might just as likely be a uglification parameter substitution error. Your use case is by no means unique and is likely the most frequent way people use it. – simme Nov 16 '16 at 17:05
  • well, I've tried including the concatenated file (without the ngannotate/uglify versions) but it's the same... meaning the order is the issue. – Daniel Nov 16 '16 at 18:38