Skip to content

Commit

Permalink
build: add redirect aliases for cjs (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Feb 19, 2022
1 parent 41ec6f0 commit 7d806d9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ versions.json
/docs/.vitepress/dist
/docs/api/typedoc.json
/lib
/locale

# Faker
TAGS
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"CHANGELOG.md",
"CHANGELOG_old.md",
"dist",
"locale",
"tsconfig.json"
],
"scripts": {
Expand Down
16 changes: 16 additions & 0 deletions scripts/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
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
Expand Down

0 comments on commit 7d806d9

Please sign in to comment.