如何在 Gulp 中命令编译 javascript 个文件

How to order the compiling of javascript files in Gulp

您好,我正在尝试修复在我的 Gulp 任务中编译的 js 文件的顺序。

我需要的顺序:

'/_sources/js/libs/*.js'
'/_sources/js/plugins/*.js'
'/_sources/js/custom/*.js'
'/_components/*.js'

问题是自定义文件夹包含一个 custom particlesJS 脚本,而 main particlesJS 脚本位于插件文件夹中。因此,如果 自定义脚本 最终在编译的 js 文件中的 main particlesJS 之上,一切都会中断。

我尝试用 gulp-orderevent-stream 重新排序,但 .order 似乎不起作用,仍然编译错误顺序:

function compile_js(minify, folder) {
    var jsLibs = gulp.src(folder+'/_sources/js/libs/*.js');
    var jsPlugins = gulp.src(folder+'/_sources/js/plugins/*.js');
    var jsCustom = gulp.src(folder+'/_sources/js/custom/*.js');
    var jsComponents = gulp.src(folder+'/_components/*.js');

    return es.merge(jsLibs, jsPlugins, jsComponents, jsCustom)
        .pipe(order([
            folder+'/_sources/js/libs/*.js',
            folder+'/_sources/js/plugins/*.js',
            folder+'/_sources/js/custom/*.js',
            folder+'/_components/*.js'
        ]))
        .pipe(concat('bitage_scripts.js'))
        .pipe(gulpif(minify, uglify()))
        .pipe(gulp.dest(folder+'/_assets/js'));
};

接下来我尝试了streamqueue:

function compile_js(minify, folder) {
    var jsLibs = gulp.src(folder+'/_sources/js/libs/*.js');
    var jsPlugins = gulp.src(folder+'/_sources/js/plugins/*.js');
    var jsCustom = gulp.src(folder+'/_sources/js/custom/*.js');
    var jsComponents = gulp.src(folder+'/_components/*.js');

    return streamqueue({ objectMode: true },
        gulp.src([
            jsLibs,
            jsPlugins,
            jsCustom]),
        gulp.src([jsComponents]).pipe(sass())
    )
    .pipe(concat('bitage_scripts.js'))
    .pipe(gulpif(minify, uglify()))
    .pipe(gulp.dest(folder+'/_assets/js'));
};

抛出了这个错误:Error: Invalid glob argument: [object Object],[object Object],[object Object]

任务:

// Development task
gulp.task('devsite', function () {
    minify = false;
    return compile_js(minify, 'public');
});

任何 thoughts/suggestions?

试试这个。

function compile_js(minify, folder) {
  var jsLibs = gulp.src(folder+'/_sources/js/libs/*.js');
  var jsPlugins = gulp.src(folder+'/_sources/js/plugins/*.js');
  var jsCustom = gulp.src(folder+'/_sources/js/custom/*.js');
  var jsComponents = gulp.src(folder+'/_components/*.js');

  return streamqueue({ objectMode: true },
    jsLibs,
    jsPlugins,
    jsCustom,
    jsComponents
  )
  .pipe(concat('bitage_scripts.js'))
  .pipe(gulpif(minify, uglify()))
  .pipe(gulp.dest(folder+'/_assets/js'));
};

gulp.src(gulp.src('folder+'/_source/something')) 没有意义。