diff options
| author | Shinigami <[email protected]> | 2022-02-19 23:56:06 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-19 23:56:06 +0100 |
| commit | 7d806d9a0b9914f9e0ce0c11e529bdd8ae116fc4 (patch) | |
| tree | e18f343d6a7c3945f9a719ad673078bbb9a1cd4a /scripts | |
| parent | 41ec6f08784afc2a674568328a0ea2bfb033a411 (diff) | |
| download | faker-7d806d9a0b9914f9e0ce0c11e529bdd8ae116fc4.tar.xz faker-7d806d9a0b9914f9e0ce0c11e529bdd8ae116fc4.zip | |
build: add redirect aliases for cjs (#520)
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/bundle.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/scripts/bundle.ts b/scripts/bundle.ts index 793f27a1..6d1b7b74 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 |
