Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: just read filenames of locales #1090

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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