gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 16:28:23 25 4
gpt4 key购买 nike

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

我需要的订单:

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

问题是自定义文件夹包含自定义颗粒JS脚本,而主颗粒JS脚本位于插件文件夹内。因此,如果自定义脚本最终位于编译后的js文件中的主粒子JS上方,则一切都会中断。

我尝试使用 gulp-order 重新排序。 event-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'));
};

抛出此错误:错误:无效的全局参数:[object Object],[object Object],[object Object]

任务:

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

有什么想法/建议吗?

最佳答案

试试这个。

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')) 没有意义。

关于javascript - 如何在 Gulp 中命令编译 javascript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28522916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com