1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| const args = require("minimist")(process.argv.slice(2)); const { context } = require("esbuild");
const { resolve } = require("path");
const format = args.f || "global";
const pkg = require(resolve(__dirname, `../package.json`));
const outputFormat = format.startsWith("global") ? "iife" : format == "cjs" ? "cjs" : "esm";
const outFile = resolve(__dirname, `../dist/MusicPlayer.${format}.js`);
const plugins = [ { name: "music-player", setup(build) { let count = 0; build.onEnd((result) => { if (count++ === 0) console.log("first build~~~~~"); else console.log("subsequent build"); }); }, }, ]; context({ entryPoints: [resolve(__dirname, `../src/index.ts`)], outfile: outFile, bundle: true, sourcemap: true, format: outputFormat, globalName: pkg.buildOptions?.name, platform: format === "cjs" ? "node" : "browser", plugins, }) .then((ctx) => { ctx.serve({ servedir: ".", port: 8002, }); return ctx; }) .then((ctx) => ctx.watch());
|