-
Notifications
You must be signed in to change notification settings - Fork 4
/
babel.config.js
68 lines (65 loc) · 1.71 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';
// Grab the env in the same fashion as Babel core
const env = process.env.BABEL_ENV || 'default';
const presetReact = require('@babel/preset-react');
// Define shared configuration
const DEFAULT_PLUGINS = [
['@babel/plugin-proposal-class-properties', {loose: true}],
'@babel/plugin-transform-destructuring',
['@babel/plugin-proposal-object-rest-spread', {loose: true}]
];
const PRESET_ENV_CONFIG = {
loose: true
};
const PRESET_ENV_CONFIG_MOD_FALSE = {
...PRESET_ENV_CONFIG,
modules: false
};
const TRANSFORM_IMPORT_CONFIG = {
original: '^(.+?)\\.less$',
replacement: '$1.css'
};
const environments = {
default: {
presets: [
[require.resolve('@babel/preset-env'), PRESET_ENV_CONFIG],
presetReact
],
plugins: DEFAULT_PLUGINS,
comments: false
},
esm: {
presets: [
[require.resolve('@babel/preset-env'), PRESET_ENV_CONFIG_MOD_FALSE],
presetReact
],
plugins: [
...DEFAULT_PLUGINS,
['transform-rename-import', TRANSFORM_IMPORT_CONFIG]
],
comments: false
},
modern: {
presets: [
[require.resolve('@babel/preset-env'), PRESET_ENV_CONFIG],
presetReact
],
plugins: [
...DEFAULT_PLUGINS,
['transform-rename-import', TRANSFORM_IMPORT_CONFIG]
],
comments: false
},
umd: {
presets: [
[require.resolve('@babel/preset-env'), PRESET_ENV_CONFIG_MOD_FALSE],
presetReact
],
plugins: DEFAULT_PLUGINS,
comments: false
}
};
module.exports = (api) => {
api.cache(false);
return environments[env];
};