Skip to content

Commit 665839b

Browse files
committed
build: add redirect aliases for cjs
1 parent 9138ea0 commit 665839b

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ versions.json
7474
/docs/.vitepress/dist
7575
/docs/api/typedoc.json
7676
/lib
77+
/locale
7778

7879
# Faker
7980
TAGS

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"CHANGELOG.md",
4949
"CHANGELOG_old.md",
5050
"dist",
51+
"locale",
5152
"tsconfig.json"
5253
],
5354
"scripts": {

scripts/bundle.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
import { buildSync } from 'esbuild';
22
import { sync as globSync } from 'glob';
3+
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
34
import locales from '../src/locales';
45

56
console.log('Building dist for node (cjs)...');
7+
8+
// Generate entry-points for cjs compatibility
9+
const localeDir = 'locale';
10+
if (existsSync(localeDir)) {
11+
rmSync(localeDir, { recursive: true, force: true });
12+
}
13+
mkdirSync(localeDir);
14+
for (const locale of Object.keys(locales)) {
15+
writeFileSync(
16+
`${localeDir}/${locale}.js`,
17+
`module.exports = require('../dist/cjs/locale/${locale}');\n`,
18+
{ encoding: 'utf8' }
19+
);
20+
}
21+
622
buildSync({
723
entryPoints: globSync('./src/**/*.ts'),
824
// We can use the following entry points when esbuild supports cjs+splitting

0 commit comments

Comments
 (0)