Skip to content

Commit

Permalink
build: just read filenames of locales
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Jun 18, 2022
1 parent 080e51d commit 5f59f76
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions scripts/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { buildSync } from 'esbuild';
import { sync as globSync } from 'glob';
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
import locales from '../src/locales';
import {
existsSync,
mkdirSync,
readdirSync,
rmSync,
writeFileSync,
} from 'node:fs';

const target = ['ES2019', 'node14.6'];

const locales = readdirSync('./src/locales').filter(
(file) => !file.includes('.')
);

console.log('Building dist for node (cjs)...');

// Generate entry-points for cjs compatibility
const localeDir = 'locale';
const target = ['ES2019', 'node14.6'];

if (existsSync(localeDir)) {
rmSync(localeDir, { recursive: true, force: true });
}
mkdirSync(localeDir);
for (const locale of Object.keys(locales)) {
for (const locale of locales) {
writeFileSync(
`${localeDir}/${locale}.js`,
`module.exports = require('../dist/cjs/locale/${locale}');\n`,
Expand All @@ -26,7 +36,7 @@ buildSync({
// We can use the following entry points when esbuild supports cjs+splitting
// entryPoints: [
// './src/index.ts',
// ...Object.keys(locales).map((locale) => `./src/locale/${locale}.ts`),
// ...locales.map((locale) => `./src/locale/${locale}.ts`),
// ],
outdir: './dist/cjs',
bundle: false, // Creates 390MiB bundle ...
Expand All @@ -39,10 +49,11 @@ buildSync({
});

console.log('Building dist for node type=module (esm)...');

buildSync({
entryPoints: [
'./src/index.ts',
...Object.keys(locales).map((locale) => `./src/locale/${locale}.ts`),
...locales.map((locale) => `./src/locale/${locale}.ts`),
],
outdir: './dist/esm',
bundle: true,
Expand Down

0 comments on commit 5f59f76

Please sign in to comment.