[英]How to exclude all node_modules directories from gulp src stream?
我的 monorepo 包含很多node_modules
目錄。 我想清理所有 js 文件,不包括node_modules
目錄中的那些文件。 不幸的是,我無法讓它工作。 這是我對 Gulp 的嘗試:
import { src } from 'gulp';
import * as clean from 'gulp-clean';
const SRC_DIR = '../../apps/lambda/';
function clean() {
return src([SRC_DIR + '**/*.js', '!' + SRC_DIR + '**/node_module/*.js'], {
read: false,
})
.pipe(clean({ force: true }));
}
上面的 function 也會從node_modules
目錄中刪除 js 文件。
import { src } from 'gulp';
import * as clean from 'gulp-clean';
import * as ignore from 'gulp-ignore';
const SRC_DIR = '../../apps/lambda/';
function clean() {
return src(SRC_DIR + '**/*.js', {
read: false,
})
.pipe(ignore.exclude('**/node_module/*.js'))
.pipe(clean({ force: true }));
}
再次,同樣的問題。
我究竟做錯了什么?
更新:我找到了答案: https://stackoverflow.com/a/62708117/6910860
我找到了答案。 Globbing 還需要排除父目錄。 這是正確的代碼:
import { src } from 'gulp';
import * as clean from 'gulp-clean';
const SRC_DIR = '../../apps/lambda/';
function clean() {
return src(
[
SRC_DIR + '**/*.js',
'!' + SRC_DIR + '**/node_modules/',
'!' + SRC_DIR + '**/node_modules/**/*.js',
],
{
read: false,
}
).pipe(clean({ force: true }));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.