-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
build-bundle.mjs
106 lines (96 loc) · 2.92 KB
/
build-bundle.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
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
#!/usr/bin/env node
import fs from 'node:fs/promises'
import path from 'node:path'
import chalk from 'chalk'
import esbuild from 'esbuild'
import babel from 'esbuild-plugin-babel'
const UPPY_ROOT = new URL('../', import.meta.url)
const PACKAGES_ROOT = new URL('./packages/', UPPY_ROOT)
function buildBundle (srcFile, bundleFile, { minify = true, standalone = '', plugins, target, format } = {}) {
return esbuild.build({
bundle: true,
sourcemap: true,
entryPoints: [srcFile],
outfile: bundleFile,
platform: 'browser',
minify,
keepNames: true,
plugins,
target,
format,
}).then(() => {
if (minify) {
console.info(chalk.green(`✓ Built Minified Bundle [${standalone}]:`), chalk.magenta(bundleFile))
} else {
console.info(chalk.green(`✓ Built Bundle [${standalone}]:`), chalk.magenta(bundleFile))
}
})
}
await fs.mkdir(new URL('./uppy/dist', PACKAGES_ROOT), { recursive: true })
await fs.mkdir(new URL('./@uppy/robodog/dist', PACKAGES_ROOT), { recursive: true })
await fs.mkdir(new URL('./@uppy/locales/dist', PACKAGES_ROOT), { recursive: true })
const methods = [
buildBundle(
'./packages/uppy/index.mjs',
'./packages/uppy/dist/uppy.min.mjs',
{ standalone: 'Uppy (ESM)', format: 'esm' },
),
buildBundle(
'./packages/uppy/bundle.mjs',
'./packages/uppy/dist/uppy.min.js',
{ standalone: 'Uppy', format: 'iife' },
),
buildBundle(
'./packages/uppy/bundle-legacy.mjs',
'./packages/uppy/dist/uppy.legacy.min.js',
{
standalone: 'Uppy (with polyfills)',
target: 'es5',
plugins:[babel({
config:{
compact: false,
highlightCode: false,
inputSourceMap: true,
browserslistEnv: 'legacy',
presets: [['@babel/preset-env', {
loose: false,
targets: { ie:11 },
useBuiltIns: 'entry',
corejs: { version: '3.15', proposals: true },
}]],
},
})],
},
),
buildBundle(
'./packages/@uppy/robodog/bundle.js',
'./packages/@uppy/robodog/dist/robodog.min.js',
{ standalone: 'Robodog' },
),
]
// Build minified versions of all the locales
const localesModules = await fs.opendir(new URL('./@uppy/locales/src/', PACKAGES_ROOT))
for await (const dirent of localesModules) {
if (!dirent.isDirectory() && dirent.name.endsWith('.js')) {
const localeName = path.basename(dirent.name, '.js')
methods.push(
buildBundle(
`./packages/@uppy/locales/src/${localeName}.js`,
`./packages/@uppy/locales/dist/${localeName}.min.js`,
{ minify: true },
),
)
}
}
// Add BUNDLE-README.MD
methods.push(
fs.copyFile(
new URL('./BUNDLE-README.md', UPPY_ROOT),
new URL('./uppy/dist/README.md', PACKAGES_ROOT),
),
)
await Promise.all(methods).then(() => {
console.info(chalk.yellow('✓ JS bundles 🎉'))
}, (err) => {
console.error(chalk.red('✗ Error:'), chalk.red(err.message))
})