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: ["inkjs"], assetNames: "assets/[dir][name]-[hash]", metafile: true, loader: { ".woff": "dataurl", ".woff2": "dataurl", ".png": "file", ".jpg": "file", ".webp": "file", ".basis": "file", ".ktx2": "file", ".ktx": "file", ".stage": "text", }, plugins: [], } const esmOptions = { ...baseOptions, format: "esm", target: ["esnext"], outfile: pkg.module, define: { global: "window", }, } const cjsOptions = { ...baseOptions, platform: "node", outfile: pkg.main, } async function build() { new Generator({ // relative to tsconfig rootdir entry: 'index.ts', output: 'dist/index.d.ts', }).generate() if (shouldWatch) { let esmContext = await esbuild.context(esmOptions) let csjContext = await esbuild.context(cjsOptions) await Promise.all([esmContext.watch(), csjContext.watch()]) return } await esbuild.build(esmOptions) await esbuild.build(cjsOptions) } build()