forked from tilap/craco-sass-resources-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (35 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module.exports = {
overrideWebpackConfig: ({ webpackConfig, pluginOptions }) => {
// Check webpack config
if (
!webpackConfig ||
!webpackConfig.module ||
!webpackConfig.module.rules ||
typeof webpackConfig.module.rules !== 'object'
) {
throw new Error('craco-sass-resources-loader error: no valid webpackConfig.module.rules');
}
// Add the loader rule where needed
const output = {...webpackConfig};
Object.keys(output.module.rules).forEach((ruleKey, ruleIndex) => {
const rule = output.module.rules[ruleKey];
if (Object.prototype.hasOwnProperty.call(rule, 'oneOf')) {
rule.oneOf.forEach((oneOf, oneOfIndex) => {
if (
oneOf.test && oneOf.use &&
(`${oneOf.test}`.includes('scss') || `${oneOf.test}`.includes('sass'))
) {
const options = pluginOptions && pluginOptions.resources ? {
resources: pluginOptions.resources,
} : {};
output.module.rules[ruleIndex].oneOf[oneOfIndex].use.push({
loader: 'sass-resources-loader',
options,
})
}
})
}
})
return output;
}
};