1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/svg-sprite-loader/lib/utils/normalize-rule.js

34 lines
764 B
JavaScript
Raw Normal View History

2023-12-18 13:12:25 +08:00
const { parseQuery } = require('loader-utils');
const isWebpack1 = require('./is-webpack-1');
/**
* webpack 1 compat rule normalizer
* @param {string|Rule} rule (string - webpack 1, Object - webpack 2)
* @return {Object<loader: string, options: Object|null>}
*/
function normalizeRule(rule) {
if (!rule) {
throw new Error('Rule should be string or object');
}
let data;
if (typeof rule === 'string') {
const parts = rule.split('?');
data = {
loader: parts[0],
options: parts[1] ? parseQuery(`?${parts[1]}`) : null
};
} else {
const options = isWebpack1 ? rule.query : rule.options;
data = {
loader: rule.loader,
options: options || null
};
}
return data;
}
module.exports = normalizeRule;