作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要在当前 gulp 文件中的“默认”任务之前运行另一个 gulp 文件。有没有针对这种情况的 gulp 插件。
最佳答案
您可以使用 child_process.exec(...)
使用 CLI API 从控制台运行这两个 gulp 任务。有Gulp.run
但该功能已被弃用,并将被移除。
此代码段将连续运行下面的两个 gulp 文件。
运行两个 gulp 文件.js
运行:node run-two-gulp-files.js
./gulpfile.js
取决于 ./other-thing-with-gulpfile/gulpfile.js
var exec = require('child_process').exec;
// Run the dependency gulp file first
exec('gulp --gulpfile ./other-thing-with-gulpfile/gulpfile.js', function(error, stdout, stderr) {
console.log('other-thing-with-gulpfile/gulpfile.js:');
console.log(stdout);
if(error) {
console.log(error, stderr);
}
else {
// Run the main gulp file after the other one finished
exec('gulp --gulpfile ./gulpfile.js', function(error, stdout, stderr) {
console.log('gulpfile.js:');
console.log(stdout);
if(error) {
console.log(error, stderr);
}
});
}
});
var gulp = require('gulp');
var replace = require('gulp-replace');
gulp.task('file1-txt', function() {
return gulp.src('file1.txt')
.pipe(replace(/foo/g, 'bar'))
.pipe(gulp.dest('dest'));
});
gulp.task('default', ['file1-txt']);
var gulp = require('gulp');
var replace = require('gulp-replace');
gulp.task('file2-txt', function() {
return gulp.src('file2.txt')
.pipe(replace(/baz/g, 'qux'))
.pipe(gulp.dest('../dest'));
});
gulp.task('default', ['file2-txt']);
关于gulp - 如何在当前 gulpfile 中运行另一个 gulpfile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27997321/
我是一名优秀的程序员,十分优秀!