-
Notifications
You must be signed in to change notification settings - Fork 2
/
config-overrides.js
57 lines (48 loc) · 1.43 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
const { getLoader, loaderNameMatches } = require('react-app-rewired');
const rewireLess = require('react-app-rewire-less');
const VariablesOutput = require('less-plugin-variables-output');
const fs = require('fs');
const path = require('path');
const less = require('less');
module.exports = function override(config, env) {
const tsLoader = getLoader(
config.module.rules,
rule => loaderNameMatches(rule, 'ts-loader')
);
if (!tsLoader) {
console.log ('ts-loader was not found');
return config;
}
const tsImportPluginFactory = require('ts-import-plugin');
tsLoader.options = {
...tsLoader.options,
getCustomTransformers: () => ({
before: [
tsImportPluginFactory({
libraryName: 'antd',
libraryDirectory: 'es',
style: true
})]
})
};
const themeLessFileName = path.resolve(path.join(__dirname, 'src', 'theme.less'));
const lessContent = fs.readFileSync(themeLessFileName, 'utf8');
let lessOverrides = {};
const lessPluginOptions = {
callback: (vars) => lessOverrides = vars
};
less.render (lessContent, {
plugins: [
new VariablesOutput(lessPluginOptions)
]
}, (error, output) => {
if (error) {
throw new Error('Error occured during the parsing of the theme.less file: ' + error);
return config;
}
});
config = rewireLess.withLoaderOptions({
modifyVars: lessOverrides
})(config, env);
return config;
}