Javascript Angular ng annotate不适用于babel
我正在使用browserify和babel编译我的js文件,我也想要ng annotate插件,但它不工作,你知道为什么吗 吞咽任务:Javascript Angular ng annotate不适用于babel,javascript,angularjs,gulp,Javascript,Angularjs,Gulp,我正在使用browserify和babel编译我的js文件,我也想要ng annotate插件,但它不工作,你知道为什么吗 吞咽任务: browserify(config.js.src, { debug: true }) .transform(babel.configure({ ignore: /vendor\// })) .bundle() .pipe(source(config.js.mainFileName)) .pipe(buffer()) .
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;
我认为在你的情况下,巴贝尔正在剥离评论。Ng annotate与已编译的es5代码一起工作,并且必须知道要注释什么。您可以在运行babel时使用
注释:true
和压缩:false
来保留注释或使用字符串文字:
constructor($http) {
"ngInject";
this.name = 'avi';
}
“不工作”是什么意思?会发生什么?不会发生,dist代码中没有$inject。为什么不在browserify转换之前运行ng annotate?
注释:true
实际上是默认值。在我的特殊案例中,我发现我正在使用babel将ES6模块转换为commonjs,而babel在我的注释和输出的函数YourClass之间插入了一些语句,这是令人沮丧的注释。我的解决方案还将“ngInject”
文本放在函数的顶部。