-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix(loader): add support for issuer when matching rules With Webpack v2 one can use svg-sprite-loader for JavaScript/JSX modules while still using other loaders in other contexts (CSS for example). This is possible by using the "issuer" configuration for loader rules. For use with Webpack v1 an error will still occur. Fixes #149 * test(loader): add coverage for Webpack v1+2 handling of issuer in rules This adds coverage to the loader tests so that the "issuer" attribute on loader rules is honored when evaluating Webpack v2 config. For v1 configuration the issuer attribute is ignored and the previous errors are expected.
- Loading branch information
1 parent
0640a40
commit 5d21b2f
Showing
3 changed files
with
37 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
const ruleMatcher = require('webpack/lib/ModuleFilenameHelpers').matchObject; | ||
const isWebpack1 = require('./is-webpack-1'); | ||
const RuleSet = !isWebpack1 ? require('webpack/lib/RuleSet') : null; | ||
|
||
/** | ||
* @param {string} request | ||
* @param {Rule[]} rules Webpack loaders config | ||
* @return {Rule[]} | ||
*/ | ||
function getMatchedRules(request, rules) { | ||
return rules.filter(rule => ruleMatcher(rule, request)); | ||
function getMatchedRules(request, rules, issuer) { | ||
const matchedRules = rules.filter(rule => ruleMatcher(rule, request)); | ||
|
||
if (issuer) { | ||
return matchedRules.filter((rule) => { | ||
// If rule doesn't have an issuer or RuleSet is not available | ||
if (!rule.issuer || !RuleSet) { | ||
return true; | ||
} | ||
|
||
const matcher = RuleSet.normalizeCondition(rule.issuer); | ||
return matcher(issuer); | ||
}); | ||
} | ||
|
||
return matchedRules; | ||
} | ||
|
||
module.exports = getMatchedRules; |
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