forked from faker-js/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.ts
56 lines (52 loc) · 1.49 KB
/
bundle.ts
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
import { buildSync } from 'esbuild';
import { sync as globSync } from 'glob';
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
import locales from '../src/locales';
console.log('Building dist for node (cjs)...');
// Generate entry-points for cjs compatibility
const localeDir = 'locale';
if (existsSync(localeDir)) {
rmSync(localeDir, { recursive: true, force: true });
}
mkdirSync(localeDir);
for (const locale of Object.keys(locales)) {
writeFileSync(
`${localeDir}/${locale}.js`,
`module.exports = require('../dist/cjs/locale/${locale}');\n`,
{ encoding: 'utf8' }
);
}
buildSync({
entryPoints: globSync('./src/**/*.ts'),
// We can use the following entry points when esbuild supports cjs+splitting
// entryPoints: [
// './src/index.ts',
// ...Object.keys(locales).map((locale) => `./src/locale/${locale}.ts`),
// './src/iban.ts',
// './src/mersenne.ts',
// ],
outdir: './dist/cjs',
bundle: false, // Creates 390MiB bundle ...
sourcemap: false,
minify: true,
// splitting: true, // Doesn't work with cjs
format: 'cjs',
platform: 'node',
target: 'node12',
});
console.log('Building dist for node type=module (esm)...');
buildSync({
entryPoints: [
'./src/index.ts',
...Object.keys(locales).map((locale) => `./src/locale/${locale}.ts`),
'./src/iban.ts',
'./src/mersenne.ts',
],
outdir: './dist/esm',
bundle: true,
sourcemap: false,
minify: true,
splitting: true,
format: 'esm',
target: 'node12.20',
});