gulp-ng-annotate - 如何使用它?
gulp-ng-annotate - how to use it?
我想缩小我的大 angular 项目。
使用 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 的新手,如有任何信息,我们将不胜感激。
gulp-ng-annotate
不会尝试在您的应用程序中查找其他文件。在管道传输到 gulp-ng-annotate 或 src
所有文件之前,您需要将您的应用程序连接到单个 app.js
文件中,然后将它们传递给`gulp- ng-注释。
例如连接方法:
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 与 watch 任务一起单独完成。
我想缩小我的大 angular 项目。
使用 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 的新手,如有任何信息,我们将不胜感激。
gulp-ng-annotate
不会尝试在您的应用程序中查找其他文件。在管道传输到 gulp-ng-annotate 或 src
所有文件之前,您需要将您的应用程序连接到单个 app.js
文件中,然后将它们传递给`gulp- ng-注释。
例如连接方法:
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 与 watch 任务一起单独完成。