forked from contentful/contentful.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.babelrc.js
106 lines (91 loc) · 2.39 KB
/
.babelrc.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
102
103
104
105
106
// About this file:
// Babel 7 introduces .babelrc.js files. The .babelrc file can be removed when Babel 7 is released. (https://github.com/babel/babel/pull/4892)
// Babel 7 will also remove the 'env' option --> https://github.com/babel/babel/issues/4539#issuecomment-284870486
var env = process.env.BABEL_ENV || process.env.NODE_ENV
var defaultBabelPresetEnvConfig = {
// No module transformation, webpack will take care of this if necessary.
'modules': false
}
// Latest browsers
var browserBabelPresetEnvConfig = Object.assign({}, defaultBabelPresetEnvConfig, {
'targets': {
'browsers': [
'last 2 versions',
'not ie < 13',
'not android < 50'
]
}
})
// Legacy browsers
var legacyBabelPresetEnvConfig = Object.assign({}, defaultBabelPresetEnvConfig, {
'targets': {
'browsers': [
'last 5 versions',
'not ie < 10'
]
}
})
// Node
var nodeBabelPresetEnvConfig = Object.assign({}, defaultBabelPresetEnvConfig, {
'targets': {
'node': '4.7'
}
})
// Combined node and browser environment for es6 modules version and tests
var modulesBabelPresetEnvConfig = Object.assign({}, defaultBabelPresetEnvConfig, {
'targets': Object.assign(legacyBabelPresetEnvConfig.targets, nodeBabelPresetEnvConfig.targets)
})
var testBabelPresetEnvConfig = Object.assign({}, modulesBabelPresetEnvConfig, {
// Tests need to transform modules
'modules': 'commonjs'
})
var plugins = [
'transform-object-rest-spread',
'lodash',
['inline-replace-variables', {
// Inject version number into code
'__VERSION__': require('./package.json').version
}]
]
var babelConfig = {
plugins
}
if (env === 'browser') {
babelConfig = Object.assign(babelConfig, {
'presets': [
['env', browserBabelPresetEnvConfig]
]
})
}
if (env === 'legacy') {
babelConfig = Object.assign(babelConfig, {
'presets': [
['env', legacyBabelPresetEnvConfig]
]
})
}
if (env === 'modules') {
babelConfig = Object.assign(babelConfig, {
'presets': [
['env', modulesBabelPresetEnvConfig]
]
})
}
if (env === 'node') {
babelConfig = Object.assign(babelConfig, {
'presets': [
['env', nodeBabelPresetEnvConfig]
]
})
}
if (env === 'test') {
babelConfig = Object.assign(babelConfig, {
'presets': [
['env', testBabelPresetEnvConfig]
],
'plugins': babelConfig.plugins.concat([
'rewire'
])
})
}
module.exports = babelConfig