forked from shockpkg/icon-encoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
69 lines (66 loc) · 1.19 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
'use strict';
const {name, version, engines} = require('./package.json');
const node = engines.node
.split(/[^\d.]+/)
.filter(s => s.length)
.map(s => [...s.split('.').map(s => +s || 0), 0, 0].slice(0, 3))
.sort((a, b) => a[2] - b[2])
.sort((a, b) => a[1] - b[1])
.sort((a, b) => a[0] - b[0])[0]
.join('.');
module.exports = api => {
const env = api.env();
api.cache(() => env);
const modules = env === 'esm' ? false : 'commonjs';
const ext = modules ? '.js' : '.mjs';
const presets = [];
const plugins = [];
presets.push([
'@babel/preset-env',
{
modules,
exclude: ['proposal-dynamic-import'],
targets: {
node
}
}
]);
presets.push(['@babel/preset-typescript']);
if (modules === 'commonjs') {
plugins.push([
'@babel/plugin-transform-modules-commonjs',
{
importInterop: 'node'
}
]);
}
plugins.push([
'esm-resolver',
{
source: {
extensions: [
[['.js', '.mjs', '.jsx', '.mjsx', '.ts', '.tsx'], ext]
]
}
}
]);
plugins.push([
'search-and-replace',
{
rules: [
{
search: '#{NAME}',
replace: name
},
{
search: '#{VERSION}',
replace: version
}
]
}
]);
return {
presets,
plugins
};
};