-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (59 loc) · 1.84 KB
/
app.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
const { declare } = require('@babel/helper-plugin-utils');
module.exports = declare((api, options) => {
const isDevelopment =
typeof options.development === 'boolean'
? options.development
: api.cache.using(() => process.env.NODE_ENV === 'development');
const isTest = api.env('test');
const presetEnvConfig = isTest
? {}
: {
useBuiltIns: 'entry',
corejs: {
version: 3,
proposals: true,
},
};
const presetReactConfig = {
development: isDevelopment,
runtime: 'automatic', // automatic will be the default value when Babel@8 comes.
};
const presetTsConfig = {
isTSX: true,
allExtensions: true,
};
const presets = [
['@babel/preset-env', presetEnvConfig],
['@babel/preset-react', presetReactConfig],
['@babel/preset-typescript', presetTsConfig],
];
const transformRuntimeConfig = {
...presetEnvConfig,
};
// avoid babel warnings
delete transformRuntimeConfig.useBuiltIns;
const decoratorsConfig = options.legacyDecorators
? { legacy: true }
: { decoratorsBeforeExport: true };
const classPropertiesConfig = { loose: !!options.legacyDecorators };
const plugins = [
['@babel/plugin-transform-runtime', transformRuntimeConfig],
['@babel/plugin-proposal-decorators', decoratorsConfig],
['@babel/plugin-proposal-class-properties', classPropertiesConfig],
['@babel/plugin-proposal-private-methods', classPropertiesConfig],
[
'@babel/plugin-proposal-private-property-in-object',
classPropertiesConfig,
],
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-syntax-dynamic-import',
'babel-plugin-add-module-exports',
'babel-plugin-lodash',
];
if (isDevelopment) plugins.push('react-refresh/babel');
return {
presets,
plugins,
sourceMap: 'inline',
};
});