forked from popcodeorg/popcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
56 lines (51 loc) · 1.25 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
const fs = require('fs');
const path = require('path');
module.exports = api => {
let targets;
const isJest = api.caller(caller => caller && caller.name === 'babel-jest');
api.cache.using(() => `${isJest}:${process.env.NODE_ENV}`);
if (isJest) {
targets = {node: 'current'};
} else if (process.env.DEBUG === 'true') {
targets = {browsers: 'last 1 Chrome version'};
} else {
targets = JSON.parse(
fs
.readFileSync(path.resolve(__dirname, 'config/browsers.json'))
.toString(),
);
}
const plugins = ['@babel/syntax-dynamic-import'];
if (isJest) {
plugins.push('babel-plugin-dynamic-import-node');
}
return {
presets: [
'@babel/preset-react',
[
'@babel/preset-env',
{
targets,
modules: isJest ? 'auto' : false,
useBuiltIns: 'entry',
corejs: 3,
},
],
],
plugins,
compact: false,
overrides: isJest
? [
{
test: './node_modules/html-inspector/html-inspector.js',
plugins: [
[
'transform-globals',
{import: {'html-inspector/window': {window: 'default'}}},
],
],
},
]
: [],
};
};