Angular的ng annotate不能与babel一起工作



我正在使用browserify和babel来编译我的js文件,我想要ng注释插件,但它不工作,任何想法为什么?

gulp任务:

  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;

我认为在你的情况下,Babel是剥离注释。Ng-annotate与编译的es5代码一起工作,并且必须以某种方式知道要注释什么。您可以使用comments: truecompact: false运行babel以保留注释,或者使用字符串字面值:

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

最新更新