我的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 }));
}
上面的函数也从目录中删除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
我找到了答案。通配还需要排除父目录。这是正确的代码:
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 }));
}