Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support for ignore patterns #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ webpack --json | webpack-unused

# if your source code is in a directory, like src/ pass that as a flag:
webpack --json | webpack-unused -s src

# if your you want to ignore some files that are not used by webpack - like specs you can pass ignore flag (glob):
webpack --json | webpack-unused -s src -i **/*.spec.js

# or even multiple glob patterns:
webpack --json | webpack-unused -s src -i '**/*.spec.js, lib/*.js'
```

## Notes/Caveats:
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ const argv = require('yargs')
.alias('s', 'src')
.describe('s', 'Directory of source code')
.default('s', '.')
.alias('i', 'ignore')
.describe('i', 'Ignore pattern')
.default('i', '')
.help('h')
.alias('h', 'help')
.argv;

// specify which directory to look in for source files
const srcDir = Path.resolve(argv.src);

// specify ignore pattern(s)
const ignorePattern = argv.ignore.split(', ');

const isWebpackLocal = (path) => {
return (path.indexOf('./') === 0 && path.indexOf('./~/') === -1);
};
Expand All @@ -34,7 +40,7 @@ const selectLocalModules = (webpack) => {
};

const findAllLocalFiles = (cwd) => {
return Glob2('!(node_modules)/**/*.*', { cwd: srcDir })
return Glob2('!(node_modules)/**/*.*', { cwd: srcDir, ignore: ignorePattern })
.then((files) => files.map((f) => Path.join(srcDir, f)));
};

Expand Down