diff --git a/.gitignore b/.gitignore index 414655adbac..dba79bf0e48 100644 --- a/.gitignore +++ b/.gitignore @@ -74,6 +74,7 @@ versions.json /docs/.vitepress/dist /docs/api/typedoc.json /lib +/locale # Faker TAGS diff --git a/package.json b/package.json index 5404cef51b7..94ccac85852 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "CHANGELOG.md", "CHANGELOG_old.md", "dist", + "locale", "tsconfig.json" ], "scripts": { diff --git a/scripts/bundle.ts b/scripts/bundle.ts index 793f27a1436..6d1b7b749ba 100644 --- a/scripts/bundle.ts +++ b/scripts/bundle.ts @@ -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