这是我的gulp脚本。 我没有任何问题。 但我改变了配置。当我跑这个时我得到了错误。 '合并复制组件'任务不起作用。为了使其工作,我必须执行上一个任务。但我认为任务不会执行和完成,但与后来的任务同时工作。
我该如何解决这个问题?我想同步完成两项任务。
var gulp = require('gulp'),
//usemin = require('gulp-usemin'),
wrap = require('gulp-wrap'),
connect = require('gulp-connect'),
watch = require('gulp-watch'),
//minifyCss = require('gulp-minify-css'),
minifyJs = require('gulp-uglify'),
concat = require('gulp-concat'),
less = require('gulp-less'),
rename = require('gulp-rename'),
html2js = require('gulp-html2js');
//minifyHTML = require('gulp-minify-html');
var clean = require('gulp-clean');
var paths = {
index: '../admin/index.html',
///theme_scripts: '../admin/assets/theme-js/**/*.*',
scripts: '../admin/assets/js/**/*.*',
styles: '../admin/assets/css/**/*.*',
images: '../admin/assets/img/**/*.*',
less: '../admin/assets/less/*.less',
html_templates: '../admin/app/**/*.tpl.html',
app_data: '../admin/app/**/*.json',
app_js: '../admin/app/**/*.js',
// app_js_ordered: [ '/admin/app/app.module.js', '/admin/app/**/!(app.module).js'], // all files that end in .js EXCEPT foobar*.js
bower_fonts: 'src/components/**/*.{ttf,eot,woff,eof,svg}'
};
gulp.task('clean', function () {
return gulp.src('../src/main/webapp')
.pipe(clean({force: true}))
.pipe(clean());
});
/**
* Handle bower components from index
*/
gulp.task('usemin', function() {
return gulp.src(paths.index)
// .pipe(usemin({
// js: [minifyJs(), 'concat'],
// css: [minifyCss({keepSpecialComments: 0}), 'concat'],
// }))
.pipe(gulp.dest('../src/main/webapp/'));
});
/**
* Copy assets
*/
gulp.task('build-assets', ['copy-bower_fonts']);
gulp.task('copy-bower_fonts', function() {
return gulp.src(paths.bower_fonts)
.pipe(rename({
dirname: '/fonts'
}))
.pipe(gulp.dest('../src/main/webapp'));
});
/**
* Handle custom files
*/
gulp.task('build-custom', ['html-template', 'merge-copy-components' , 'custom-images', 'app-js','move-json-data','custom-js', /* 'theme-js',*/ 'lib-less' ,'custom-less','lib-css']);
gulp.task('merge-copy-components', function() {
// when it deploys, we have to filter must-necessary files
gulp.src('src/components/**/*.*')
.pipe(gulp.dest('../admin/assets/components'))
//copy-merge-components
return gulp.src('../admin/assets/components/**/*.*')
.pipe(gulp.dest('../src/main/webapp/components'));
});
gulp.task('custom-images', function() {
return gulp.src(paths.images)
.pipe(gulp.dest('../src/main/webapp/img'));
});
gulp.task('move-json-data', function() {
return gulp.src(paths.app_data)
.pipe(gulp.dest('../src/main/webapp/json'));
});
gulp.task('app-js', function() {
return gulp.src(paths.app_js)
//.pipe(minifyJs())
.pipe(concat('redca-ias.concat.js'))
.pipe(gulp.dest('../src/main/webapp/js'));
});
//gulp.task('theme-js', function() {
// return gulp.src(paths.theme_scripts)
// //.pipe(minifyJs())
// .pipe(concat('dashboard.min.js'))
// .pipe(gulp.dest('../src/main/webapp/js'));
//});
gulp.task('custom-js', function() {
return gulp.src(paths.scripts)
// .pipe(minifyJs())
// .pipe(concat('openpms.concat.js'))
.pipe(gulp.dest('../src/main/webapp/js'));
});
gulp.task('custom-less', function() {
return gulp.src(paths.less)
.pipe(less())
.pipe(gulp.dest('../src/main/webapp/css'));
});
gulp.task('lib-css', function() {
return gulp.src(paths.styles)
.pipe(gulp.dest('../src/main/webapp/css'));
});
gulp.task('lib-less', function() {
return gulp.src(paths.less)
.pipe(less())
.pipe(gulp.dest('../src/main/webapp/css'));
});
gulp.task('html-template', function() {
gulp.src(paths.html_templates)
.pipe(html2js(
{
base : '../admin/app/',
outputModuleName: 'RedCA',
useStrict: true
}
))
.pipe(concat('redca-ias.templates.js'))
.pipe(gulp.dest('../src/main/webapp/js'))
})
/*
gulp.task('inplace-app', function() {
return gulp.src('../src/main/webapp/js')
.pipe(gulp.dest('../build/inplaceWebapp/js'));
});
*/
/**
* Watch custom files
*/
gulp.task('watch', function() {
gulp.watch([paths.html_templates], ['html-template']);
gulp.watch([paths.images], ['custom-images']);
gulp.watch([paths.styles], ['custom-less']);
gulp.watch([paths.scripts], ['custom-js']);
///gulp.watch([paths.theme_scripts], ['theme-js']);
gulp.watch([paths.index], ['usemin']);
gulp.watch([paths.app_js], ['app-js']);
gulp.watch([paths.app_data], ['move-json-data']);
// for test
// gulp.watch(['../src/main/webapp/js'], ['inplace-app']);
});
/**
* Live reload server
*/
gulp.task('webserver', function() {
connect.server({
root: '../src/main/webapp/',
livereload: true,
port: 5555
});
});
gulp.task('livereload', function() {
// gulp.src(['../src/main/webapp/**/*.*'])
// .pipe(watch())
// .pipe(connect.reload());
});
/**
* Gulp tasks
*/
gulp.task('build', ['usemin', 'build-custom', 'build-assets', ]);
gulp.task('default', ['build', 'webserver', 'livereload', 'watch']);
答案 0 :(得分:3)
创建任务:
gulp.task('filet', function() {
gulp.src('src/components/**/*.*')
.pipe(gulp.dest('../admin/assets/components'));
});
然后将其添加到您的另一个任务的依赖项
gulp.task('merge-copy-components', ['filter'], function() {
...
这将确保'过滤'任务在&merge-copy-components'。
之前结束