/* eslint-disable */ const fs = require('fs') const esbuild = require('esbuild') const name = process.env.npm_package_name || '' async function main() { if (!fs.existsSync('./dist')) { fs.mkdirSync('./dist') } try { esbuild.buildSync({ entryPoints: ['./src/index.ts'], outdir: 'dist/cjs', minify: true, bundle: true, format: 'cjs', target: 'es6', jsxFactory: 'React.createElement', jsxFragment: 'React.Fragment', tsconfig: './tsconfig.build.json', external: ['react', 'react-dom'], }) esbuild.buildSync({ entryPoints: ['./src/index.ts'], outdir: 'dist/esm', minify: true, bundle: true, format: 'esm', target: 'es6', tsconfig: './tsconfig.build.json', jsxFactory: 'React.createElement', jsxFragment: 'React.Fragment', external: ['react', 'react-dom'], }) for (const file of ['package.json', 'README.md']) { fs.copyFile(file, `dist/${file}`, fs.constants.COPYFILE_EXCL, (err) => { if (err) throw err }) } console.log(`✔ ${name}: Built package.`) } catch (e) { console.log(`× ${name}: Build failed due to an error.`) console.log(e) } } main()