-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-overrides.js
74 lines (67 loc) · 2.09 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
69
70
71
72
73
74
const { getBabelLoader, injectBabelPlugin } = require('react-app-rewired');
const math = require('remark-math');
const katex = require('remark-html-katex');
const map = require('unist-util-map');
const HTMLtoJSX = require('htmltojsx');
const htmlToJSXConverter = new HTMLtoJSX({
createClass: false,
});
const isJSXRegex = /<\/?[A-Z]/;
const htmlToJSXPlugin = () =>
function transformer(ast) {
const astMapped = map(ast, node => {
if (node.type === 'html' && !isJSXRegex.test(node.value)) {
return { ...node, value: htmlToJSXConverter.convert(node.value) };
}
return node;
});
return astMapped;
};
module.exports = (config, env) => {
config = injectBabelPlugin('transform-decorators-legacy', config);
config = injectBabelPlugin('@babel/plugin-proposal-do-expressions', config);
config = injectBabelPlugin('@babel/plugin-proposal-optional-chaining', config);
config = injectBabelPlugin('lodash', config);
if (env === 'production') {
console.log('⚡ Production build with optimization ⚡');
config = injectBabelPlugin('closure-elimination', config);
config = injectBabelPlugin('@babel/plugin-transform-react-inline-elements', config);
config = injectBabelPlugin('@babel/plugin-transform-react-constant-elements', config);
} else {
config = injectBabelPlugin(
[
'flow-runtime',
{
assert: true,
annotate: true,
},
],
config,
);
}
// remove eslint in eslint, we only need it on VSCode
config.module.rules.splice(1, 1);
const babelLoader = getBabelLoader(config.module.rules);
config.module.rules.map(rule => {
if (typeof rule.test !== 'undefined' || typeof rule.oneOf === 'undefined') {
return rule;
}
rule.oneOf.unshift({
test: /\.mdx?$/,
use: [
{
loader: babelLoader.loader,
options: babelLoader.options,
},
{
loader: '@mdx-js/loader',
options: {
mdPlugins: [math, katex, [htmlToJSXPlugin, {}]],
},
},
],
});
return rule;
});
return config;
};