Skip to content

Instantly share code, notes, and snippets.

@bashmish
Last active September 23, 2017 15:58
Show Gist options
  • Save bashmish/e76c07532bde97b44c68713bf56dca42 to your computer and use it in GitHub Desktop.
Save bashmish/e76c07532bde97b44c68713bf56dca42 to your computer and use it in GitHub Desktop.
minimatch / glob exclude directory (folder, dir)
const minimatch = require('minimatch');
const paths = [
'build/my-file.js',
'build/my-component/my-file.js',
'node_modules/my-file.js',
'node_modules/my-module/my-file.js',
'my-file.js',
'src/my-file.js',
'src/sub-dir/my-file.js'
];
const filteredPaths = paths.filter(path => minimatch(path, '{,!(build|node_modules)/**/}*'));
filteredPaths.forEach(path => console.log(path));
// my-file.js
// src/my-file.js
// src/sub-dir/my-file.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment