This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 386
/
babel.config.js
83 lines (78 loc) · 2.14 KB
/
babel.config.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
75
76
77
78
79
80
81
82
83
const wrapWarningWithDevCheck = require('./scripts/babel/wrap-warning-with-dev-check');
const extensionResolver = require('./scripts/babel/extension-resolver');
const isES = process.env.BABEL_ENV === 'es';
const isRollup = process.env.BABEL_ENV === 'rollup';
const clean = (x) => x.filter(Boolean);
module.exports = (api) => {
const isTest = api.env('test');
const targets = {};
if (!isTest) {
targets.browsers = ['last 2 versions', 'ie >= 9'];
} else {
targets.node = true;
}
return {
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
modules: !isES && !isRollup ? 'commonjs' : false,
targets,
},
],
'@babel/preset-react',
],
plugins: clean([
'@babel/plugin-proposal-class-properties',
isRollup && 'babel-plugin-transform-react-remove-prop-types',
wrapWarningWithDevCheck,
[
'inline-replace-variables',
{
__DEV__: {
type: 'node',
replacement: "process.env.NODE_ENV !== 'production'",
},
},
],
isES && [
extensionResolver,
{
// For verification, see test/module/packages-are-es-modules.mjs
modulesToResolve: [
// InstantSearch.js/es is an ES Module, so needs complete paths,
'instantsearch.js',
// React-DOM also fails if the paths are incomplete
'react-dom',
// `use-sync-external-store` also fails if the paths are incomplete
'use-sync-external-store',
],
},
],
]),
overrides: [
{
test: 'packages/*',
plugins: [
[
'@babel/plugin-transform-runtime',
{
corejs: false,
helpers: true,
regenerator: false,
useESModules: isES || isRollup,
},
],
],
},
{
test: 'packages/react-instantsearch-dom-maps',
plugins: clean([
'@babel/plugin-syntax-dynamic-import',
!isRollup && 'babel-plugin-dynamic-import-node',
]),
},
],
};
};