-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbabel.config.js
68 lines (57 loc) · 1.36 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
"use strict";
// Babel config for both web and Node.js
// console.log(process.env.NODE_ENV);
// console.log(process.env.BROWSERSLIST_ENV);
const isDefined = value => value !== undefined && value !== null;
const isWebpack = caller => caller?.name === 'babel-loader' && caller?.target === 'web';
const determineBrowserslistEnv = (api) => {
const browserslistEnv = isDefined(process.env.BROWSERSLIST_ENV)
? process.env.BROWSERSLIST_ENV
: api.caller(isWebpack) ? 'production' : 'test';
console.log('browserslistEnv = ', browserslistEnv);
return browserslistEnv;
};
module.exports = api => ({
presets: [
[
'@babel/preset-env',
{
// targets are provided by Browserslist
// see https://babeljs.io/docs/en/babel-preset-env#browserslist-integration
browserslistEnv: determineBrowserslistEnv(api),
useBuiltIns: 'usage',
corejs: 3,
debug: false,
},
],
'@babel/preset-typescript',
'@babel/preset-react',
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-default-from',
],
env: {
production: {
presets: [],
plugins: [],
},
test: {
presets: [],
plugins: [],
},
development: {
presets: [],
plugins: api.caller(isWebpack)
? ['react-hot-loader/babel']
: [],
},
},
ignore: [
'**/*.no-babel.js',
/node_modules/,
/test\//,
'**/dist',
],
sourceMaps: true,
});