forked from nusmodifications/nusmods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
62 lines (53 loc) · 1.68 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
const pkgJson = require('./package.json');
module.exports = (api) => {
api.cache.using(() => process.env.NODE_ENV);
const IS_PROD = api.env('production');
const IS_DEV = api.env('development');
const IS_TEST = api.env('test');
const presets = [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
targets: IS_TEST ? { node: true } : { browsers: pkgJson.browserslist },
modules: IS_TEST ? 'commonjs' : false,
useBuiltIns: 'usage',
corejs: pkgJson.dependencies['core-js'],
// Exclude transforms that make all code slower
// See https://github.com/facebook/create-react-app/pull/5278
exclude: ['transform-typeof-symbol'],
},
],
['@babel/preset-react', { development: !IS_PROD }],
];
const plugins = [
'babel-plugin-lodash',
'@babel/plugin-syntax-dynamic-import',
// Deviate from spec, but Object.defineProperty is expensive
// See https://github.com/facebook/create-react-app/issues/4263
['@babel/plugin-proposal-class-properties', { loose: true }],
];
if (IS_DEV || IS_PROD) {
plugins.push(['@babel/plugin-proposal-object-rest-spread', { useBuiltIns: true }]);
}
if (IS_DEV) {
plugins.push('react-hot-loader/babel');
}
if (IS_PROD) {
// React Optimize plugins
plugins.push(
'@babel/plugin-transform-react-inline-elements',
'@babel/plugin-transform-react-constant-elements',
'babel-plugin-transform-react-remove-prop-types',
'babel-plugin-transform-react-class-to-function',
);
}
if (IS_TEST) {
plugins.push('babel-plugin-dynamic-import-node');
}
return {
sourceType: 'unambiguous',
presets,
plugins,
};
};