[英]How can i combine two gulp tasks
I am using gulp
to compile my typescript files and create the output.js
file. 我正在使用
gulp
来编译我的打字稿文件并创建output.js
文件。
Is it possible to have a single task which compiles typescript file and concatenates it with angular libraries? 是否可以使用单个任务编译typescript文件并将其与角度库连接?
Here's what my current file looks like (below). 这是我当前文件的样子(如下)。 First it's running a typescript task which creates the
output.js
file and then it runs a scripts task which concats the script plugin files and output.js
. 首先,它运行一个typescript任务,创建
output.js
文件,然后运行脚本任务,该任务将脚本插件文件和output.js
。
'use strict';
var gulp = require('gulp')
var paths = {
distScriptsDir: '../../Themes/mastter/Scripts',
srcScriptsPlugins: [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/angular/angular.min.js',
'node_modules/angular-route/angular-route.min.js',
'node_modules/angular-translate/dist/angular-translate.min.js',
'node_modules/angular-translate/dist/angular-translate-loader-url/angular-translate-loader-url.min.js',
'node_modules/angular-bootstrap/dist/ui-bootstrap-tpls.js',
'Scripts/angular-sticky.min.js',
'Scripts/dragme.js',
'Scripts/jasny-bootstrap.min.js',
'node_modules/lodash/dist/lodash.min.js',
'node_modules/angular-google-maps/dist/angular-google-maps.min.js'
],
srcScriptsFile: [
'output.js'
]
};
//typescript
gulp.task('typescript', function () {
var ts = require('gulp-typescript');
var tsResult = gulp.src( 'all.ts')
.pipe(ts({
noImplicitAny: true,
out: 'output.js'
}));
return tsResult.js.pipe(gulp.dest(''));
});
// scripts task
gulp.task('scripts', function () {
var concat = require('gulp-concat'),
plumber = require('gulp-plumber'),
uglify = require('gulp-uglify');
return gulp.src(paths.srcScriptsPlugins.concat(paths.srcScriptsFile))
.pipe(plumber({
errorHandler: function (e) {
console.log(e.toString());
this.emit('end');
}
}))
// .pipe(uglify())
.pipe(concat('main.js'))
.pipe(gulp.dest(paths.distScriptsDir));
});
// default task
gulp.task('default', [
'typescript',
'scripts'
]);
I use a watch tasks for this that has a bunch of gulp.watch
inside it. 我使用了一个监视任务,里面有一堆
gulp.watch
。 One for watching the .ts change and run the typescript compiler that will output a js file in whatever location and another gulp.watch
that watches the .js files and run script task. 一个用于观察.ts更改并运行typescript编译器,它将在任何位置输出js文件,另一个
gulp.watch
.js文件并运行脚本任务。 In that case, things will get automated by the watch and you don't have to combine the task into one task. 在这种情况下,手表会使事情自动化,您不必将任务合并为一个任务。
gulp.task('watch', function() {
gulp.watch(['dir/*.ts','otherdir/*.ts',...], ['typescript']);
gulp.watch(['dir/*.js','otherdir/*.js',...], ['scripts']); //make sure to include the .ts result folder...
});
try run-sequence . 尝试运行序列 。 Below is a simple example.
下面是一个简单的例子。
gulp.task('task1', function(callback) { setTimeout(function() { console.log('task1 is done'); callback() }, 1000); }); gulp.task('task2', function(callback) { setTimeout(function() { console.log('task2 is done'); callback() }, 2000); }); gulp.task('tk12', function(callback) { return runSequence('task1', 'task2', callback); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.