-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
96 lines (87 loc) · 2.02 KB
/
Copy pathesbuild.config.mjs
File metadata and controls
96 lines (87 loc) · 2.02 KB
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
import { build } from 'esbuild'
import { readFileSync, rmSync } from 'node:fs'
const pkg = JSON.parse(readFileSync('./package.json', 'utf8'))
const version = pkg.version || '0.0.0'
const banner = {
js: `/*
* snapDiff
* v${version}
* Author: Juan Martin Muda
* License: MIT
*/`,
}
const common = {
bundle: true,
sourcemap: false,
logLevel: 'info',
banner,
}
/** Legacy IIFE for direct <script> include. */
async function buildLegacy() {
await build({
...common,
entryPoints: ['src/index.js'],
outfile: 'dist/snapdiff.js',
globalName: 'snapDiff',
platform: 'neutral',
minify: true,
target: ['es2020'],
})
}
/** ESM bundle for bundlers / CDNs / modern browsers. */
async function buildESM() {
await build({
...common,
entryPoints: ['src/index.js'],
outfile: 'dist/snapdiff.mjs',
format: 'esm',
minify: true,
splitting: false,
})
}
/** Subpath ESM bundles (subset of public exports that are stable & pure). */
async function buildSubpaths() {
await build({
...common,
entryPoints: {
'diff': 'src/diff.js',
'static-report': 'src/static-report.js',
},
outdir: 'dist',
outExtension: { '.js': '.mjs' },
format: 'esm',
minify: true,
splitting: false,
})
}
/**
* Auto-bootstrap IIFE bundle for "drop the script" workflows.
* Loads snapdom dynamically at runtime — keeps this bundle small and lets the
* user pin or self-host snapdom via the data-snapdom-url attribute.
*/
async function buildAuto() {
await build({
...common,
entryPoints: ['src/auto.js'],
outfile: 'dist/snapdiff-auto.js',
format: 'iife',
globalName: 'snapDiffAuto',
minify: true,
target: ['es2020'],
platform: 'browser',
})
}
async function main() {
try { rmSync('dist', { recursive: true, force: true }) } catch { /* ok */ }
await Promise.all([
buildLegacy(),
buildESM(),
buildSubpaths(),
buildAuto(),
])
}
main().catch((err) => {
// eslint-disable-next-line no-console
console.error(err)
process.exit(1)
})