Gulp regular expression filter main-bower files not working

Why is the second array, bowerFiles , not filtered only into javascript files.

 var gulp = require('gulp'); var mainBowerFiles = require('main-bower-files'); gulp.task('default', function () { var unfiltered = mainBowerFiles(); console.log('unfiltered files:', unfiltered); // 11 FILES //var jsRegEx = /js$/i; // tried this way too... var jsRegEx = new RegExp('js$', 'i'); var bowerFiles = mainBowerFiles(jsRegEx); console.log('bower files:', bowerFiles); // 11 FILES }); 

I tried to imitate what bower-main-files does here and it works.

+5
source share
1 answer

You do not need to create RegExp to filter files with main-bower-files .

In fact, you can just pass an array or a glob string to check for .js files only:

 gulp.task('default', function () { var bowerFiles = mainBowerFiles('**/*.js'); console.log('bower files: ', bowerFiles); }); 

If you really want to use a regular expression, you need to use the filter parameter, you cannot pass it as an argument directly:

 gulp.task('default', function () { var bowerFiles = mainBowerFiles({ filter: new RegExp('.*js$', 'i') }); console.log('bower files: ', bowerFiles); }); 
+10
source

Source: https://habr.com/ru/post/1214261/


All Articles