// @ts-check
const esbuild = require('esbuild');
const { writeFileSync } = require('node:fs');

(async () => {
  const result = await esbuild.build({
    outbase: 'src',
    entryPoints: ['./src/index.js', './src/app.js'],
    sourcemap: 'linked',
    outdir: './dist',
    write: true,
    assetNames: '[name]',
    platform: 'node',
    logLevel: 'info',
    bundle: true,
    metafile: true,
    minify: false,
    define: {
      'global.ESBUILD': 'true',
    },
    loader: {
      '.md': 'text',
    },
    external: ['canvas'],
  });

  // For bundle analysis
  writeFileSync('meta.json', JSON.stringify(result.metafile));
})();
