-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbabel.config.umd.mjs
63 lines (50 loc) · 1.43 KB
/
babel.config.umd.mjs
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
import fs from 'fs'
import { basename, dirname, extname, join, normalize } from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const dir = join(__dirname, './dist/es')
/** @type {Map<string, string[]>} */
const moduleIds = new Map
function getModuleId(/** @type {string} */name) {
const file = basename(name, '.js')
if (file == 'index') return ['sa-lambda']
return ['sa-lambda', file]
}
function getDoduleIds(/** @type {string} */dir) {
const files = fs.readdirSync(dir)
for (const file of files) {
const path = normalize(join(dir, file))
if (extname(path) == '') {
getDoduleIds(path)
continue
}
const id = getModuleId(path)
moduleIds.set(path, id)
}
}
getDoduleIds(dir)
const globals = Object.fromEntries([...moduleIds.entries()].flatMap(([k, id]) => {
return [
[id.join('/'), id.join('.')],
[`.${k.substring(dir.length).replace(/\/\//g, '/')}`, id.join('.')]
]
}))
export default {
moduleIds: true,
getModuleId(/** @type {string} */name) {
const r = getModuleId(name).join('/')
return r
},
plugins: [
['@babel/plugin-transform-modules-umd', {
globals: globals,
exactGlobals: true
}],
['babel-plugin-add-import-extension', {
extension: 'js'
}],
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-proposal-optional-chaining'
]
}