shift73k/assets_old/node_modules/svg-sprite-loader/lib/utils/get-matched-rule-4.js

23 lines
677 B
JavaScript
Raw Normal View History

/* eslint-disable import/no-unresolved */
// eslint-disable-next-line import/no-extraneous-dependencies
const RuleSet = require('webpack/lib/RuleSet');
const flattenAndExtractUse = rules => rules.reduce((pre, rule) => {
if ('rules' in rule || 'oneOf' in rule) {
return pre.concat(flattenAndExtractUse(rule.rules || rule.oneOf));
}
return pre.concat(rule.use || []);
}, []);
module.exports = (compiler) => {
const rawRules = compiler.options.module.rules;
const { rules } = new RuleSet(rawRules);
const rule = flattenAndExtractUse(rules)
.find((item) => {
return /svg-sprite-loader/.test(item.loader);
}) || {};
return rule.options || {};
};