【问题标题】:gulp-ng-annotate - how to use it?gulp-ng-annotate - 如何使用它?
【发布时间】:2016-03-16 21:27:52
【问题描述】:

我想缩小我的大型 Angular 项目。

使用角度 1.5.0。

我正在尝试使用模块 gulp-ng-annotate 这样做。

var gulp = require('gulp');
var ngAnnotate = require('gulp-ng-annotate');

gulp.task('default', function () {
return gulp.src('../www-myalcoholist-com-angular/model/app.js')
    .pipe(ngAnnotate())
    .pipe(gulp.dest('dist'));
});

当我执行这个 nodejs 脚本时,它会静默失败。或者......好吧......它什么也没做。

我只给了它主 app.js 文件作为参数。我可以给它所有的项目吗?

当我从终端运行 ng-annotate 时,它​​会在我的项目中正确添加注释.. 好吧.. 我希望 :)

那么为什么这个脚本会失败呢?

我是 gulp 的新手,所以任何信息都将不胜感激。

【问题讨论】:

    标签: angularjs gulp gulp-ng-annotate


    【解决方案1】:

    gulp-ng-annotate 不会尝试在您的应用程序中查找其他文件。您需要将您的应用程序连接到单个 app.js 文件中,然后再分别管道到 gulp-ng-annotate 或 src 所有文件,然后将它们传递给`gulp-ng-annotate。

    例如concat 方法:

    var gulp = require('gulp');
    var ngAnnotate = require('gulp-ng-annotate');
    var concat = require('gulp-concat');
    
    gulp.task('default', function () {
     return gulp.src('../www-myalcoholist-com-angular/model/**/*.js')
        .pipe(concat('app.js'))
        .pipe(ngAnnotate())
        .pipe(gulp.dest('dist'));
    });
    

    【讨论】:

    • 谢谢你的回答,不幸的是结果是一样的。我没有收到任何错误,它什么也没做。立即退出,退出代码为 0。我错过了什么?
    • 啊,我需要用 gulp 执行它,我用 nodejs 执行它。谢谢一切正常!
    【解决方案2】:

    一个示例配置 -

    gulp.task('app', function() {
        return gulp.src([
           // './bower_components/angular/angular.min.js',
           // './bower_components/angular-sanitize/angular-sanitize.min.js',
           //'./bower_components/angular-ui-select/dist/select.min.js',
           // './bower_components/angular-ui-router/release/angular-ui-router.min.js',
            './components/**/*.js'])
            .pipe(plumber())
            .pipe(count('## js-files selected'))
            .pipe(concat('./app/all.min.js', {newLine: ';'}))
            .pipe(ngAnnotate({
                // true helps add where @ngInject is not used. It infers.
                // Doesn't work with resolve, so we must be explicit there
                add: true
            }))
            .pipe(gulp.dest('./dist'));
    });
    

    这将生成一个串联的构建 js 文件。我已将供应商 js 文件分开,但您可以以任何您喜欢的方式拥有它。

    P.S - 任何其他任务,例如 Linting 与 watch 任务一起单独完成。

    【讨论】:

      猜你喜欢
      • 2017-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-05
      相关资源
      最近更新 更多