-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbabel.config.js
87 lines (82 loc) · 1.62 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
84
85
86
87
console.log('NODE_ENV:', process.env.NODE_ENV);
// common definition
const common = {
presets: [],
plugins: [],
env: {
production: {
plugins: ['transform-react-remove-prop-types'],
},
},
ignore: ['node_modules/**'],
};
let presets = [];
switch (process.env.NODE_ENV) {
case 'es':
// es6
presets = ['@babel/react'];
// presets = [['@babel/env', { targets: { esmodules: true } }], '@babel/react'];
break;
case 'production':
// production
presets = ['@babel/env', '@babel/react'];
break;
default:
presets = ['next/babel'];
// prevent next9.0.2 compile error
delete common.ignore;
break;
}
const productionPlugins = [
'add-module-exports',
[
'import',
{
libraryName: '@material-ui/core',
libraryDirectory: '',
camel2DashComponentName: false,
},
'tree-shaking-mui-core',
],
[
'import',
{
libraryName: '@material-ui/core/styles',
libraryDirectory: '',
camel2DashComponentName: false,
},
'tree-shaking-mui-styles',
],
[
'import',
{
libraryName: '@material-ui/core/colors',
libraryDirectory: '',
camel2DashComponentName: false,
},
'tree-shaking-mui-colors',
],
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
[
'@babel/plugin-transform-runtime',
{
helpers: false,
regenerator: true,
},
],
];
// merge
const babelConfig = {
...common,
presets,
env: {
es: {
plugins: productionPlugins,
},
production: {
plugins: productionPlugins,
},
},
};
module.exports = babelConfig;