build.mjs
1 import fs from 'node:fs'; 2 import path from 'node:path'; 3 import esbuild from 'esbuild'; 4 import { rimraf } from 'rimraf'; 5 6 /** 7 * @param i18nPath {string} 8 */ 9 export async function build(i18nPath) { 10 fs.cpSync(i18nPath, path.resolve('lib', 'i18n.ts')); 11 12 await esbuild.build({ 13 entryPoints: ['./index.ts'], 14 tsconfig: './tsconfig.json', 15 bundle: true, 16 packages: 'bundle', 17 target: 'es6', 18 outdir: './dist', 19 sourcemap: true, 20 format: 'esm', 21 }); 22 23 const outDir = path.resolve('..', '..', 'dist'); 24 const localePath = path.resolve(outDir, '_locales'); 25 rimraf.sync(localePath); 26 fs.cpSync(path.resolve('locales'), localePath, { recursive: true }); 27 28 console.log('I18n build complete'); 29 }