1 | const babelConfigForWebpackBuild = {
|
2 | presets: [
|
3 | [
|
4 | '@babel/preset-env',
|
5 | {
|
6 | loose: true,
|
7 | useBuiltIns: 'usage',
|
8 | corejs: 3,
|
9 | },
|
10 | ],
|
11 | '@babel/preset-react',
|
12 | ],
|
13 | plugins: [
|
14 | ['module-resolver', { root: ['./src'] }],
|
15 | '@babel/plugin-syntax-dynamic-import',
|
16 | '@babel/plugin-syntax-import-meta',
|
17 | '@babel/plugin-proposal-class-properties',
|
18 | '@babel/plugin-proposal-json-strings',
|
19 | '@babel/plugin-transform-react-constant-elements',
|
20 | ],
|
21 | };
|
22 |
|
23 | const babelConfigForJest = {
|
24 | presets: [
|
25 | [
|
26 | '@babel/preset-env',
|
27 | {
|
28 | loose: true,
|
29 | useBuiltIns: 'usage',
|
30 | corejs: 3,
|
31 | targets: {
|
32 | node: 'current',
|
33 | },
|
34 | },
|
35 | ],
|
36 | '@babel/preset-react',
|
37 | ],
|
38 | plugins: [
|
39 | ['module-resolver', { root: ['./src'] }],
|
40 | '@babel/plugin-syntax-dynamic-import',
|
41 | '@babel/plugin-syntax-import-meta',
|
42 | '@babel/plugin-proposal-class-properties',
|
43 | '@babel/plugin-proposal-json-strings',
|
44 | '@babel/plugin-transform-react-constant-elements',
|
45 | ],
|
46 | };
|
47 |
|
48 | module.exports = api => {
|
49 | const isTest = api.env('test');
|
50 |
|
51 | if (isTest) {
|
52 | return babelConfigForJest;
|
53 | }
|
54 |
|
55 | return babelConfigForWebpackBuild;
|
56 | };
|