gulp.dest未创建目标文件夹 [英] gulp.dest not creating destination folder

查看:278
本文介绍了gulp.dest未创建目标文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的gulp代码部分如下:

My gulp code looks like this, in part

gulp.src(['../application-base/**/**.js', '!../application-base/assets/**/**.js'], { base: './' })
    .pipe(gulpPlumber({
        errorHandler: function (error) {
            console.log(`\nError ${error}`);
            this.emit('end');
        }
    }))
    .pipe(gprint(filePath => "Transpiling: " + filePath.replace('..\\application-base\\', '')))
    .pipe(babel({ compact: false }))
    .pipe(gulp.dest('../application-base-transpiled/'))
    .on('end', () => done());

如果我更改

.pipe(gulp.dest('../application-base-transpiled/'))

.pipe(gulp.dest(''))

然后创建转储的文件,并覆盖原始文件.问题是

then the transpiled files are created, and overwrite the originals. The problem is that

.pipe(gulp.dest('../application-base-transpiled/'))

application-base-transpiled

如您所见,我正在使用一个基座,否则它似乎可以正常工作.

As you can see, I am using a base, which seems to work otherwise.

我想念什么?

编辑

我看得更近了,甚至连

.pipe(gulp.dest('../application-base-transpiled/'))

Gulp仍将转储后的文件放到原始位置,覆盖原始位置.我所传递的目的中有一些古尔普不喜欢的东西,并且默默地无视了.

Gulp is still placing the transpiled files into the original place, overwriting the original. There's something about the dest I'm passing that Gulp doesn't like, and is ignoring silently.

编辑2

似乎删除 base选项可以解决此问题,这与我在其他地方看到的建议相反. gulp.dest的文档并未真正讨论这一点.

It seems removing the base option solves this problem, contrary to advice I've seen elsewhere. The docs for gulp.dest don't really discuss this.

任何人都可以对此提供一些见识吗?

Can anyone provide some insight into this?

编辑3

根据Sven的回答,我尝试了

Per Sven's answer, I tried this

gulp.src(['**/**.js', '!assets/**/**.js'], { base: '../application-base' })
    .pipe(gulpPlumber({
        errorHandler: function errorHandler(error) {
            console.log('\nError ' + error);
            this.emit('end');
        }
    }))
    .pipe(gprint(filePath => "Transpiling: " + filePath.replace('..\\application-base\\', '')))
    .pipe(babel({ compact: false }))
    .pipe(gulp.dest('../application-base-transpiled/'))
    .on('end', () => done());

但是似乎基础已被忽略,并且我当前目录中的文件已被抓取并转置到位(我想要的最后一件事-幸运的是,GIT有助于消除损坏).

But it seems the base is being ignored, and the files from my own current directory are being grabbed and transpiled in place (the last thing I want - fortunately GIT was helpful in undoing the damage).

在将数组用于src时是否忽略了基本参数?

Is the base parameter ignored when using an array for src?

推荐答案

在gulp流中,文件的目标路径遵循以下伪等式:

In gulp streams the destination path of a file follows this pseudo-equation:

gulp.dest +(gulp.src,但不带base开头)=文件的目标路径

gulp.dest + (gulp.src without leading base) = dest path of file

示例:

gulp.src('src/js/foo.js', {base:'src/'}).pipe(gulp.dest('dist/'));

结果:

'dist/' +('src/js/foo.js',但不带'src/'开头)= 'dist/js/foo.js'

'dist/' + ('src/js/foo.js' without leading 'src/') = 'dist/js/foo.js'

在您的情况下:

'../application-base-transpiled/' +('../application-base/foo/bar.js'不带前导'./')= '../application-base-transpiled/../application-base/foo/bar.js'

'../application-base-transpiled/' + ('../application-base/foo/bar.js' without leading './') = '../application-base-transpiled/../application-base/foo/bar.js'

因此,文件最终位于原始目录中.

So your files end up in the original directory.

您必须将{base: '../application-base/'}传递给gulp.src()才能使示例工作.

You have to pass {base: '../application-base/'} to gulp.src() to make your example work.

注意

您仍然需要在src路径中包含'../application-base/'. base的目的是按照上面的公式操纵目标路径.它确实不是为了减少您在gulp.src中键入的击键次数.所以最终结果应该是这样的

You still need to include '../application-base/' in your src path. The purpose of base is to manipulate the dest path, per my equation above; it does not serve the purpose of lessening the number of keystrokes you type in gulp.src. So the end result should be something like this

gulp.src(['../application-base/**/**.js'], { base: '../application-base' })
        .pipe(gulpPlumber({
            errorHandler: function errorHandler(error) {
                console.log('\nError ' + error);
                this.emit('end');
            }
        }))
        .pipe(gprint(filePath => "Transpiling: " + filePath.replace('..\\application-base\\', '')))
        .pipe(babel({ compact: false }))
        .pipe(gulp.dest('../application-base-transpiled'))
        .on('end', () => done());


如果您未通过 base选项设置为gulp.src()的默认值:


If you don't pass a base option to gulp.src() a default is set:

默认值:glob启动之前的所有内容(请参见 glob2base )

这意味着将传递给gulp.src()的模式中直到第一个***的所有内容都用作base选项.由于您的图案是../application-base/**/**.js,因此您的base选项将自动变为../application-base/.

What this means is that everything up to the first ** or * in the pattern that you pass to gulp.src() is used as the base option. Since your pattern is ../application-base/**/**.js, your base option automatically becomes ../application-base/.

这篇关于gulp.dest未创建目标文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆