-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (62 loc) · 1.7 KB
/
index.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
const { declare } = require('@babel/helper-plugin-utils');
const presetEnv = [
'@babel/preset-env',
{
spec: true,
useBuiltIns: 'usage',
corejs: 3,
},
];
const sharedPresets = [presetEnv];
const sharedPlugins = [
require('@babel/plugin-syntax-dynamic-import'),
require('@babel/plugin-proposal-class-properties'),
require('@babel/plugin-proposal-nullish-coalescing-operator'),
];
const frontendCrossEnvPlugins = [
require('babel-plugin-styled-components'),
require('@babel/plugin-transform-react-jsx'),
];
const frontendProductionPlugins = [
require('babel-plugin-transform-react-remove-prop-types'),
require('babel-plugin-jsx-remove-data-test-id'),
];
const frontend = (plugins, isFrontend) => {
return isFrontend ? plugins : [];
};
const defaultOpts = {
cacheUsing: () => process.env.NODE_ENV,
frontend: false,
typescript: false,
fastRefresh: false,
};
module.exports = declare((api, opts) => {
opts = Object.assign(defaultOpts, opts);
api.assertVersion(7);
api.cache.using(opts.cacheUsing);
const config = {
presets: [...sharedPresets, require('@babel/preset-react')],
plugins: [
...sharedPlugins,
...frontend(frontendCrossEnvPlugins, opts.frontend),
],
env: {
production: {
plugins: [
...frontend(frontendProductionPlugins, opts.frontend),
require('babel-plugin-remove-debug'),
],
},
development: {
plugins: opts.fastRefresh ? [require('react-refresh/babel')] : [],
},
test: {
plugins: [require('babel-plugin-dynamic-import-node')],
},
},
};
if (opts.typescript) {
config.plugins.push(require('@babel/preset-typescript'));
}
return config;
});