forked from DestinyItemManager/DIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.cjs
115 lines (108 loc) · 3.31 KB
/
babel.config.cjs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const coreJSPackage = require('core-js/package.json');
module.exports = function (api) {
const isProduction = api.env('production');
const isTest = api.env('test');
const plugins = [
'@sigmacomputing/babel-plugin-lodash',
'babel-plugin-optimize-clsx',
'object-to-json-parse',
[
'@babel/plugin-transform-runtime',
{
useESModules: !isTest,
},
],
[
'transform-imports',
{
'@fortawesome/free-brands-svg-icons': {
transform: (member) => `@fortawesome/free-brands-svg-icons/${member}`,
preventFullImport: true,
skipDefaultConversion: true,
},
'@fortawesome/free-solid-svg-icons': {
transform: (member) => `@fortawesome/free-solid-svg-icons/${member}`,
preventFullImport: true,
skipDefaultConversion: true,
},
'@fortawesome/free-regular-svg-icons': {
transform: (member) => `@fortawesome/free-regular-svg-icons/${member}`,
preventFullImport: true,
skipDefaultConversion: true,
},
},
],
];
if (isProduction) {
plugins.push(
'@babel/plugin-transform-react-constant-elements',
'@babel/plugin-transform-react-inline-elements'
);
} else {
if (!isTest) {
plugins.push('react-refresh/babel');
}
// In dev, compile TS with babel
plugins.push(['@babel/plugin-transform-typescript', { isTSX: true, optimizeConstEnums: true }]);
}
const corejs = { version: coreJSPackage.version };
const presetEnvOptions = {
bugfixes: true,
modules: false,
loose: true,
useBuiltIns: 'usage',
corejs,
shippedProposals: true,
// Set to true and run `pnpm build:beta` to see what plugins and polyfills are being used
debug: false,
// corejs includes a bunch of polyfills for behavior we don't use or bugs we don't care about
exclude: [
// Really edge-case bugfix for Array.prototype.push and friends
'es.array.push',
'es.array.unshift',
// Remove this if we start using proposed set methods like .intersection
/esnext\.set/,
// Remove this if we start using iterator-helpers (which would be nice!)
/esnext\.iterator/,
// Not sure what exactly this is, but we have our own error-cause stuff
'es.error.cause',
// Only used when customizing JSON parsing w/ a "reviver"
'esnext.json.parse',
// Edge-case bugfixes for URLSearchParams.prototype.has, delete, and size
/web\.url-search-params/,
// Unneeded mis-detected DOMException extension
'web.dom-exception.stack',
// Not needed in worker context
'web.self',
// Mis-detected by usage of Array.prototype.at
'es.string.at-alternative',
],
};
if (isTest) {
presetEnvOptions.targets = { node: 'current' };
presetEnvOptions.modules = 'auto';
}
return {
presets: [
['@babel/preset-env', presetEnvOptions],
[
'@babel/preset-react',
{
useBuiltIns: true,
loose: true,
corejs,
runtime: 'automatic',
useSpread: true,
},
],
],
plugins,
// https://babeljs.io/docs/en/assumptions
assumptions: {
noDocumentAll: true,
noClassCalls: true,
setPublicClassFields: true,
setSpreadProperties: true,
},
};
};