-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.rescriptsrc.js
53 lines (44 loc) · 1.47 KB
/
.rescriptsrc.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
const path = require('path');
const { editWebpackPlugin } = require('@rescripts/utilities');
const customEslintConfig = config => {
const edited = editWebpackPlugin(
p => {
p.options.baseConfig.extends = undefined;
p.options.useEslintrc = true;
p.options.emitWarning = true;
p.options.ignore = true;
return p;
},
'ESLintWebpackPlugin',
config
);
return edited;
};
const createLoaderMatcher = loader => rule =>
rule.loader && rule.loader.indexOf(`${path.sep}${loader}${path.sep}`) !== -1;
const oneOfFileLoaders = config => config.module.rules.find(rule => rule.oneOf).oneOf;
const cssLoaderMatcher = createLoaderMatcher('css-loader');
const sassLoaderMatcher = createLoaderMatcher('sass-loader');
const addCamelCaseToCSSModules = config => {
const fileLoaders = oneOfFileLoaders(config);
fileLoaders.forEach(loader => {
if (loader.test && loader.use && loader.use.constructor === Array) {
loader.use.forEach(use => {
if (cssLoaderMatcher(use) && use.options.modules) {
use.options.modules.exportLocalsConvention = 'camelCase';
}
if (sassLoaderMatcher(use)) {
use.options.sassOptions = {
...use.options.sassOptions,
includePaths: [path.resolve(__dirname, 'src/scss')]
};
}
});
}
});
};
const customConfig = config => {
addCamelCaseToCSSModules(config);
return customEslintConfig(config);
};
module.exports = [customConfig];