olov / ng-annotate

Add, remove and rebuild AngularJS dependency injection annotations
MIT License
2.03k stars 150 forks source link

Remove "ngInject" prologues after adding annotations #220

Closed thorn0 closed 8 years ago

thorn0 commented 8 years ago

From readme:

Your minifier will most likely retain the "ngInject" prologues so use sed or a regexp in your build toolchain to get rid of those...

Why doesn't ng-annotate do this itself? Is there some conceptual reason, or is a PR welcome?

olov commented 8 years ago

The intent is to alter the source code minimally. Keeping the "ngInject" prologue means that it is possible to run ng-annotate on the code again, removing or refreshing annotations. I have thought about maybe adding an option to ng-annotate (off by default) to for ngInject removal but never decided for it. A PR is not necessary however feedback for whether such an option would be useful (from you and others) is appreciated!

tcmitche commented 8 years ago

I would definitely find such an option useful. I appreciate the intent behind only making the minimal changes to the code as necessary, but I think an opt-in flag for removing the "ngInject" prologues would be a great addition.

c-vetter commented 8 years ago

Same here. I think a one-way workflow should be considered a non-negligible, maybe typical, use-case.

mediastuttgart commented 8 years ago

if you are using gulp or another build system you could also use replace to remove the prologue stuff

//...
.pipe(concat('app.js'))
.pipe(annotate({ single_quotes: true, remove: true, add: true }))
.pipe(replace(/\t'ngInject';\n/g, ''))
.pipe(uglify())
//...
ghengeveld commented 8 years ago

Just for the record, here's my working Webpack loader setup:

// loaders are executed in reverse order
const loaders = [
  'string-replace?search=\'ngInject\';&replace=',
  'ng-annotate',
  'nginject?deprecate',
  'babel'
];

This babelifies, then checks for any deprecated /*@ngInject*/ syntax, then does the $inject annotations and finally removes the 'ngInject'; prologues.

olov commented 8 years ago

https://github.com/olov/ng-annotate/issues/245