-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfig-overrides.js
68 lines (58 loc) · 1.76 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
66
67
68
const {
getLoader
} = require("react-app-rewired");
const tsImportPluginFactory = require('ts-import-plugin')
const rewireCssModules = require('react-app-rewire-css-modules');
const rewireLess = require('react-app-rewire-less');
const theme = require('./theme.js');
const ruleChildren = (loader) => loader.use || loader.oneOf || Array.isArray(loader.loader) && loader.loader || []
const findIndexAndRules = (rulesSource, ruleMatcher) => {
let result = undefined
const rules = Array.isArray(rulesSource) ? rulesSource : ruleChildren(rulesSource)
rules.some((rule, index) => result = ruleMatcher(rule) ? {
index,
rules
} : findIndexAndRules(ruleChildren(rule), ruleMatcher))
return result
}
const findRule = (rulesSource, ruleMatcher) => {
const {
index,
rules
} = findIndexAndRules(rulesSource, ruleMatcher)
return rules[index]
}
const tsRuleMatcher = (rule) => rule.test && String(rule.test) === String(/\.(ts|tsx)$/);
module.exports = function override(config, env) {
// Load Antd on demand
const tsRule = findRule(config.module.rules, tsRuleMatcher)
const tsLoader = getLoader(
config.module.rules,
rule =>
rule.loader &&
typeof rule.loader === 'string' &&
rule.loader.includes('ts-loader')
);
tsLoader.options = {
transpileOnly: true,
getCustomTransformers: () => ({
before: [tsImportPluginFactory({
libraryDirectory: 'es',
libraryName: 'antd',
style: true,
})]
}),
compilerOptions: {
module: 'es2015'
}
};
tsRule.exclude = /node_modules/
// Customize Antd Theme
config = rewireLess.withLoaderOptions({
modifyVars: theme,
javascriptEnabled: true
})(config, env);
// CSS Modules
config = rewireCssModules(config, env);
return config;
}