Closed thorn0 closed 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!
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.
Same here. I think a one-way workflow should be considered a non-negligible, maybe typical, use-case.
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())
//...
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.
From readme:
Why doesn't ng-annotate do this itself? Is there some conceptual reason, or is a PR welcome?