-
-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from webpack-contrib/exclude-assets
Add option to exclude assets from the report
- Loading branch information
Showing
10 changed files
with
173 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { inspect } = require('util'); | ||
const _ = require('lodash'); | ||
|
||
exports.createAssetsFilter = createAssetsFilter; | ||
|
||
function createAssetsFilter(excludePatterns) { | ||
const excludeFunctions = _(excludePatterns) | ||
.castArray() | ||
.compact() | ||
.map(pattern => { | ||
if (typeof pattern === 'string') { | ||
pattern = new RegExp(pattern); | ||
} | ||
|
||
if (_.isRegExp(pattern)) { | ||
return (asset) => pattern.test(asset); | ||
} | ||
|
||
if (!_.isFunction(pattern)) { | ||
throw new TypeError( | ||
`Pattern should be either string, RegExp or a function, but "${inspect(pattern, { depth: 0 })}" got.` | ||
); | ||
} | ||
|
||
return pattern; | ||
}) | ||
.value(); | ||
|
||
if (excludeFunctions.length) { | ||
return (asset) => _.every(excludeFunctions, fn => fn(asset) !== true); | ||
} else { | ||
return () => true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.