-
Notifications
You must be signed in to change notification settings - Fork 1
/
.rescriptsrc.js
72 lines (56 loc) · 1.9 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const path = require('path');
const createLoaderMatcher = (loader) => (rule) => rule.loader && rule.loader.indexOf(`${path.sep}${loader}${path.sep}`) !== -1; //eslint-disable-line
const oneOfFileLoaders = (config) => config.module.rules.find((rule) => rule.oneOf).oneOf;
const cssLoaderMatcher = createLoaderMatcher('css-loader');
const sassLoaderMatcher = createLoaderMatcher('sass-loader');
const babelLoaderMatcher = createLoaderMatcher('babel-loader');
const eslintLoaderMatcher = createLoaderMatcher('eslint-loader');
const enableBabelRc = (config) => {
const fileLoaders = oneOfFileLoaders(config);
fileLoaders.forEach((loader) => {
if (babelLoaderMatcher(loader)) {
loader.options.babelrc = true;
}
});
};
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 customEslintConfig = (config) => {
config.module.rules.forEach((rule) => {
if (rule.use) {
const eslintUse = rule.use.find((use) => eslintLoaderMatcher(use));
if (eslintUse) {
eslintUse.options = {
...eslintUse.options,
baseConfig: undefined,
useEslintrc: true,
emitWarning: true,
ignore: true,
};
}
}
});
};
const customConfig = (config) => {
customEslintConfig(config);
addCamelCaseToCSSModules(config);
enableBabelRc(config);
return config;
};
module.exports = [customConfig];