1 | const { parseQuery } = require('loader-utils');
|
2 | const isWebpack1 = require('./is-webpack-1');
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | function normalizeRule(rule) {
|
10 | if (!rule) {
|
11 | throw new Error('Rule should be string or object');
|
12 | }
|
13 |
|
14 | let data;
|
15 |
|
16 | if (typeof rule === 'string') {
|
17 | const parts = rule.split('?');
|
18 | data = {
|
19 | loader: parts[0],
|
20 | options: parts[1] ? parseQuery(`?${parts[1]}`) : null
|
21 | };
|
22 | } else {
|
23 | const options = isWebpack1 ? rule.query : rule.options;
|
24 | data = {
|
25 | loader: rule.loader,
|
26 | options: options || null
|
27 | };
|
28 | }
|
29 |
|
30 | return data;
|
31 | }
|
32 |
|
33 | module.exports = normalizeRule;
|