Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove "ngInject" prologues after adding annotations #220

Closed
thorn0 opened this issue Dec 30, 2015 · 6 comments
Closed

Remove "ngInject" prologues after adding annotations #220

thorn0 opened this issue Dec 30, 2015 · 6 comments

Comments

@thorn0
Copy link

thorn0 commented Dec 30, 2015

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
Copy link
Owner

olov commented Dec 31, 2015

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
Copy link

tcmitche commented Jan 5, 2016

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
Copy link

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

@mediastuttgart
Copy link

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
Copy link

ghengeveld commented Apr 20, 2016

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
Copy link
Owner

olov commented Jun 8, 2016

#245

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants