Skip to content

Commit 58f2472

Browse files
committed
use cjs bundling
1 parent 616b3f9 commit 58f2472

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

scripts/bundle.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { buildSync } from 'esbuild';
2-
import { globSync } from 'glob';
32
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
43
import { allLocales } from '../src';
54

@@ -17,20 +16,18 @@ mkdirSync(localeDir);
1716
for (const locale of Object.keys(allLocales)) {
1817
writeFileSync(
1918
`${localeDir}/${locale}.cjs`,
20-
`module.exports = require('../dist/cjs/locale/${locale}');\n`,
19+
`module.exports = require('../dist/cjs/locale/${locale}.cjs');\n`,
2120
{ encoding: 'utf8' }
2221
);
2322
}
2423

2524
buildSync({
26-
entryPoints: globSync('./src/**/*.ts'),
27-
// We can use the following entry points when esbuild supports cjs+splitting
28-
// entryPoints: [
29-
// './src/index.ts',
30-
// ...Object.keys(locales).map((locale) => `./src/locale/${locale}.ts`),
31-
// ],
25+
entryPoints: [
26+
'./src/index.ts',
27+
...Object.keys(allLocales).map((locale) => `./src/locale/${locale}.ts`),
28+
],
3229
outdir: './dist/cjs',
33-
bundle: false, // Creates 390MiB bundle ...
30+
bundle: true, // Creates 49MiB bundle ...
3431
sourcemap: false,
3532
minify: true,
3633
// splitting: true, // Doesn't work with cjs

test/locale-imports.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { allLocales } from '../src';
55
describe.each(Object.keys(allLocales))('locale imports', (locale) => {
66
it(`should be possible to directly require('@faker-js/faker/locale/${locale}')`, () => {
77
// eslint-disable-next-line @typescript-eslint/no-var-requires
8-
const { faker } = require(`../dist/cjs/locale/${locale}`) as {
8+
const { faker } = require(`../dist/cjs/locale/${locale}.cjs`) as {
99
faker: Faker;
1010
};
1111

@@ -66,7 +66,7 @@ describe.each(Object.keys(allLocales))('locale imports', (locale) => {
6666
describe('Internal tests to cover `src/locale/*.ts`', () => {
6767
it(`should be possible to directly require('../locale/${locale}')`, () => {
6868
// eslint-disable-next-line @typescript-eslint/no-var-requires
69-
const { faker } = require(`../locale/${locale}`);
69+
const { faker } = require(`../locale/${locale}.cjs`);
7070

7171
expect(faker).toBeDefined();
7272
expect(faker.string.alpha()).toBeTypeOf('string');

0 commit comments

Comments
 (0)