gpt4 book ai didi

javascript - 有没有办法改变当前的 gulp 基础上下文?

转载 作者:行者123 更新时间:2023-11-28 07:29:16 25 4
gpt4 key购买 nike

有没有办法改变我的 gulpfile.js 中的 gulp 上下文?

现在,我正在为所有 gulp.src 添加我想要的位置前缀。但有没有办法在全局范围内改变这种情况?

这是我当前的代码:

var base = '../';
gulp.task('copy', function() {
gulp.src(base + 'sampleFile.js').pipe(gulp.dest('dist/'));
});

gulp.task('clean', function() {
del.sync([base + options.dist]);
});

这就是我正在寻找的:

gulp.base('../', function() {
gulp.task('copy', function() {
gulp.src('sampleFile.js').pipe(gulp.dest('dist/'));
});

gulp.task('clean', function() {
del.sync([options.dist]);
});
});

最佳答案

CLI 标志 --cwd 将允许您全局更改它 - 不过要做您想做的事情,您还需要为其提供 gulpfile 在您调用它的目录中的位置从,所以

gulp --gulpfile gulpfile.js --cwd ../

将替换您拥有的路径前缀。

您还可以为 gulp.src 调用创建一个选项对象,并在其上使用 cwd: base :

var opts = {cwd: '..'}

gulp.task('copy', function() {
gulp.src('sampleFile.js', opts).pipe(gulp.dest('dist/'));
});

将 Gulpfile 移动到一个目录中也可能是有意义的,在该目录中它可以更明显地访问它将要读取和写入的内容。

关于javascript - 有没有办法改变当前的 gulp 基础上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29289778/

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