Angular ng annotate does not work with babel

北城余情 提交于 2019-12-08 03:30:30

问题


I am using browserify and babel to compile my js files and i want the ng annotate plugin too but it is not working, any ideas why?

The gulp task:

  browserify(config.js.src, { debug: true })
    .transform(babel.configure({ ignore: /vendor\// }))
    .bundle()
    .pipe(source(config.js.mainFileName))
    .pipe(buffer())
    .pipe(sourcemaps.init({ loadMaps: true }))
    .pipe(ngAnnotate())
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest(config.js.dist));

class HomeController {
  // @ngInject
  constructor($http) {
    this.name = 'avi';
  }
}

export default HomeController;

回答1:


I think in your case Babel is stripping comments. Ng-annotate works with compiled es5 code and have to somehow know what to annotate. You can either run babel with comments: true and compact: false to preserve comments or use string literals:

constructor($http) {
    "ngInject";
    this.name = 'avi';
}


来源:https://stackoverflow.com/questions/30325910/angular-ng-annotate-does-not-work-with-babel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!