import * as esbuild from "esbuild" import minimist from "minimist" import npmDTS from 'npm-dts'; import pkg from "./package.json" assert { type: "json" } const { Generator } = npmDTS; const argv = minimist(process.argv.slice(2)) const shouldWatch = argv.w ? true : false const baseOptions = { entryPoints: [`src/index.ts`], sourcemap: true, bundle: true, external: ["phaser", "phaser3-rex-plugins"], assetNames: "assets/[dir][name]-[hash]", metafile: true, loader: { ".woff": "dataurl", ".woff2": "dataurl", }, plugins: [], } const esmOptions = { ...baseOptions, format: "esm", target: ["esnext"], outfile: pkg.main, define: { global: "window", }, } async function build() { new Generator({ // relative to tsconfig rootdir entry: 'index.ts', output: 'dist/index.d.ts', force: true, }).generate() if (shouldWatch) { let esmContext = await esbuild.context(esmOptions) await esmContext.watch() return } await esbuild.build(esmOptions) } build()