-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-overrides.js
65 lines (55 loc) · 1.97 KB
/
config-overrides.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const path = require("path");
const {compose, getLoader} = require("react-app-rewired");
function rewireSass(sassLoaderOptions = {}) {
return function(config, env) {
const sassExtension = /\.scss/;
const fileLoader = getLoader(
config.module.rules,
rule =>
rule.loader &&
typeof rule.loader === 'string' &&
rule.loader.indexOf(`${path.sep}file-loader${path.sep}`) !== -1
);
fileLoader.exclude.push(sassExtension);
const cssRules = getLoader(
config.module.rules,
rule => String(rule.test) === String(/\.css$/)
);
let sassRules;
if (env === "production") {
sassRules = {
test: sassExtension,
loader: [
// TODO: originally this part is wrapper in extract-text-webpack-plugin
// which we cannot do, so some things like relative publicPath
// will not work.
// https://github.com/timarney/react-app-rewired/issues/33
...cssRules.loader,
{ loader: require.resolve("sass-loader"), options: sassLoaderOptions }
]
};
} else {
sassRules = {
test: sassExtension,
use: [
...cssRules.use,
{ loader: require.resolve("sass-loader"), options: sassLoaderOptions }
]
};
}
const oneOfRule = config.module.rules.find((rule) => rule.oneOf !== undefined);
if (oneOfRule) {
oneOfRule.oneOf.unshift(sassRules);
}
else {
// Fallback to previous behaviour of adding to the end of the rules list.
config.module.rules.push(sassRules);
}
return config;
};
}
module.exports = compose(
rewireSass({
includePaths: ["src/"],
}),
);