-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-overrides.js
46 lines (40 loc) · 1.28 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
const { override } = require("customize-cra");
const StylelintPlugin = require("stylelint-webpack-plugin");
module.exports = override(
useEslintRc(".eslintrc.json", { fix: true }),
useStylelintRc(".stylelintrc.json", { fix: true })
);
// use self-made useEslintRc because we want to add options to eslint-loader
function useEslintRc(configFile, options) {
return config => {
const eslintRule = config.module.rules.filter(
r =>
r.use && r.use.some(u => u.options && u.options.useEslintrc !== void 0)
)[0];
const eslintOptions = eslintRule.use[0].options;
eslintOptions.useEslintrc = true;
eslintOptions.ignore = true;
eslintOptions.configFile = configFile;
delete eslintOptions.baseConfig;
eslintRule.use[0].options = Object.assign(eslintOptions, options);
const rules = config.module.rules.map(r =>
r.use && r.use.some(u => u.options && u.options.useEslintrc !== void 0)
? eslintRule
: r
);
config.module.rules = rules;
return config;
};
}
function useStylelintRc(configFile, options) {
return config => {
config.plugins.push(
new StylelintPlugin({
configFile,
files: ["**/*.css", "**/*.sass", "**/*.scss", "**/*.less"],
...options
})
);
return config;
};
}