【问题标题】:Gulp.js: "gulp-chug" only runs one file even when set to watching manyGulp.js:“gulp-chug”即使设置为观看多个文件也只运行一个文件
【发布时间】:2014-11-23 22:21:33
【问题描述】:

我已经开始使用 Gulp,我遇到的问题是让 gulp-chug 正常工作。

我已经按照文档中的所有内容,告诉我的 gulpfile 监视某些目录中的所有 gulpfile,而它只监视一个文件。

这是我在文档之后使用的代码...

var gulp = require('gulp');
var chug = require('gulp-chug');

gulp.task('default', function () {
    gulp.src('**/task_runner/gulpfile.js')
        .pipe(chug());
});

我什至试图看看如果我将文件路径放在一个数组中是否会有所不同...

...
    gulp.src(
        [ '**/task_runner/gulpfile.js' ]
    )
...

我也试过这个(以及 gulp.src() 中没有数组的版本)...

...
    gulp.src(
        [ 'Project_01/task_runner/gulpfile.js', 'Project_02/task_runner/gulpfile.js' ]
    )
...

...它仍然做同样的事情。

我的文件结构是这样的,

*root*
    node_modules
    gulpfile.js
    package.json
    Project_01
        css
        scss
        task_runner
    Project_02
        css
        scss
        task_runner

所有 gulpfile 在单独运行时都可以工作,但我希望它们都在一个 cmd 窗口中同时运行 gulp-chug。

这是我的 cmd 的样子,表明它只在看 Project_02,

C:\Users\WaheedJ\Desktop\UniServer\www\Practice\gulp>gulp
[14:19:40] Using gulpfile ~\Desktop\UniServer\www\Practice\gulp\gulpfile.js
[14:19:40] Starting 'default'...
[14:19:40] Finished 'default' after 6.37 ms
[gulp-chug] File is a buffer. Need to write buffer to temp file...
[gulp-chug] Writing buffer to Project_02\task_runner\gulpfile.tmp.1411996780120.
js...
[gulp-chug] Spawning process C:\Users\WaheedJ\Desktop\UniServer\www\Practice\gul
p\Project_02\task_runner\node_modules\gulp\bin\gulp.js with args C:\Users\Waheed
J\Desktop\UniServer\www\Practice\gulp\Project_02\task_runner\node_modules\gulp\b
in\gulp.js --gulpfile gulpfile.tmp.1411996780120.js default from directory C:\Us
ers\WaheedJ\Desktop\UniServer\www\Practice\gulp\Project_02\task_runner...
[gulp-chug](Project_02\task_runner\gulpfile.tmp.1411996780120.js) [14:19:42] Usi
ng gulpfile ~\Desktop\UniServer\www\Practice\gulp\Project_02\task_runner\gulpfil
e.tmp.1411996780120.js
[gulp-chug](Project_02\task_runner\gulpfile.tmp.1411996780120.js) [14:19:42] Sta
rting 'watch'...
[gulp-chug](Project_02\task_runner\gulpfile.tmp.1411996780120.js) [14:19:43] Fin
ished 'watch' after 18 ms
[14:19:43] Starting 'default'...
[14:19:43] Finished 'default' after 7.13 µs

我能做些什么来解决这个问题?

【问题讨论】:

    标签: node.js npm task gulp watch


    【解决方案1】:

    我也发生了同样的事情。现在我采用了这个解决方法:

    gulp.task('default', ['one-gulpfile', 'another-gulpfile'], function () {});
    gulp.task('one-gulpfile', function () { return gulp.src('./project-one/gulpfile.js').pipe(chug()); });
    gulp.task('another-gulpfile', function () { return gulp.src('./project-another/gulpfile.js').pipe(chug()); });
    

    基本上是一个空的默认任务,依赖于硬编码任务,每个任务运行一个 gulp 文件。

    当然不是动态的,需要维护,但我做到了,这是我目前最需要的。我希望看到chug更成熟一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-19
      • 1970-01-01
      • 1970-01-01
      • 2016-02-26
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      • 2015-09-07
      相关资源
      最近更新 更多