forked from Semantic-Org/Semantic-UI-React
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.babel-preset.js
101 lines (95 loc) · 2.62 KB
/
.babel-preset.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const { NODE_ENV } = process.env
const isESBuild = NODE_ENV === 'build-es'
const isUMDBuild = NODE_ENV === 'build-umd'
const isLibBuild = NODE_ENV === 'build' || isESBuild || isUMDBuild
const isDocsBuild = NODE_ENV === 'development' || NODE_ENV === 'production'
const browsers = [
'last 8 versions',
'safari > 8',
'firefox > 23',
'chrome > 24',
'opera > 15',
'not ie < 11',
'not ie_mob <= 11',
]
const plugins = [
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-optional-chaining', { loose: true }],
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-syntax-dynamic-import',
[
'@babel/plugin-transform-runtime',
{
regenerator: isDocsBuild,
useESModules: isESBuild,
// https://github.com/babel/babel/issues/10261
version: require('@babel/runtime/package.json').version,
},
],
// Plugins that allow to reduce the target bundle size
// `babel-plugin-lodash` is required for all kinds of modules to simplify the resolution of
// modules and avoid modules that prevent tree-shaking:
// https://github.com/lodash/lodash/issues/4119
'lodash',
// CJS modules are not tree-shakable in any bundler by default
// https://github.com/formium/tsdx#using-lodash
(isESBuild || isUMDBuild) && [
'babel-plugin-transform-rename-import',
{
replacements: [{ original: 'lodash', replacement: 'lodash-es' }],
},
],
'transform-react-handled-props',
[
'transform-react-remove-prop-types',
{
mode: isUMDBuild ? 'remove' : 'wrap',
removeImport: isUMDBuild,
},
],
// A plugin for removal of debug in production builds
isLibBuild && [
'filter-imports',
{
imports: {
'./makeDebugger': ['default'],
'../../lib': ['makeDebugger'],
},
},
],
].filter(Boolean)
module.exports = () => ({
compact: false,
presets: [
[
'@babel/env',
{
modules: isESBuild || isUMDBuild ? false : 'commonjs',
loose: true,
targets: { browsers },
},
],
'@babel/react',
],
plugins,
env: {
development: {
plugins: ['react-hot-loader/babel'],
},
test: {
plugins: [['istanbul', { include: ['src'] }]],
},
},
overrides: [
// A workaround to avoid collisions between "babel-plugin-dynamic-import-node" & "universal-import"
{
test: /react-static-routes.js/,
plugins: [
['universal-import', { disableWarnings: true }],
'@babel/plugin-transform-modules-commonjs',
],
presets: [['@babel/env', { modules: false }]],
},
],
})