forked from effector/effector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
97 lines (88 loc) · 2.33 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
88
89
90
91
92
93
94
95
96
97
//@noflow
const {resolve: resolvePath} = require('path')
const resolveSource = path => resolvePath(__dirname, 'src', path)
const aliases = {
'effector/effect': 'effect',
'effector/event': 'event',
'effector/store': 'store',
'effector/domain': 'domain',
'effector/graphite': 'graphite',
'effector/fixtures': 'fixtures',
'effector/stdlib': 'stdlib',
'effector/perf': 'perf',
'effector/watcher': 'watcher',
'effector/flags': ({isBuild}) => (isBuild ? 'flags.prod' : 'flags.dev'),
warning: 'warning',
invariant: 'invariant',
'effector-react': 'react',
'effector-vue': 'vue',
}
module.exports = api => {
// api && api.cache && api.cache.never && api.cache.never()
const env = api.cache(() => process.env.NODE_ENV)
const alias = parseAliases(aliases, {
isBuild: !!process.env.IS_BUILD,
})
if (process.env.NODE_ENV === 'test') {
alias.effector = resolvePath(__dirname, 'src')
}
const plugins = [
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
['@babel/plugin-proposal-class-properties', {loose: true}],
'macros',
[
'babel-plugin-module-resolver',
{
alias,
},
],
]
const presets = [
'@babel/preset-flow',
'@babel/preset-react',
[
'@babel/preset-env',
{
loose: true,
useBuiltIns: false,
modules: false,
shippedProposals: true,
targets: {
node: '10',
browsers: [
'last 2 Chrome versions',
'last 2 Firefox versions',
'last 2 Safari versions',
'last 2 Edge versions',
],
},
},
],
]
const overrides = [
{
test(filename) {
return filename.includes('__tests__')
},
plugins: ['./src/babel/babel-plugin'],
},
]
if (process.env.NODE_ENV === 'test' || process.env.IS_SERVER != null) {
plugins.push('@babel/plugin-transform-modules-commonjs')
}
return {plugins, presets, overrides, sourceMaps: true}
}
function parseAliases(obj, meta) {
const result = {}
for (const key in obj) {
const value = obj[key]
if (typeof value === 'string') {
result[key] = resolveSource(value)
} else {
result[key] = resolveSource(value(meta))
}
}
return result
}