我想缩小我的大角度项目。
使用角度 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 脚本时,它会静默失败。 或者...嗯..它什么都不做。
我只给了它主应用程序.js文件作为参数。 我可以给它一些如何给它所有项目吗?
当我从终端运行ng-annotate时,它正确地为我的项目添加了注释..嗯..我希望:)
那么为什么这个脚本会失败呢?
我是大口大口的新手,所以任何信息将不胜感激。
gulp-ng-annotate
不会尝试在应用程序中查找其他文件。您需要在管道连接到gulp-ng-annotate之前将应用程序连接到单个app.js
文件中,或者单独src
所有文件并将它们传递给'gulp-ng-annotate。
例如,连接方法:
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'));
});
配置示例 -
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)与监视任务一起单独完成。