diff --git a/.gitignore b/.gitignore index ed80ad4..022ba3b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ c/*.dump c/*.hex c/*.bin tmp +*.tgz diff --git a/build.js b/build.js index e6223ba..f0d0bd4 100644 --- a/build.js +++ b/build.js @@ -57,8 +57,9 @@ function runTSC(args) { } const files = { - "built/ml4f.js": "src/main.ts", - "built/ml4f.cjs": "src/main.ts", + "built/ml4f.js": "src/ml4f.ts", + "built/ml4f.cjs": "src/ml4f.ts", + "built/ml4f.mjs": "src/ml4f.ts", "built/pxtml4f.js": "pxt/extension.ts", "built/pxtml4f.cjs": "pxt/extension.ts", "built/cli.cjs": "cli/src/cli.ts", @@ -68,18 +69,21 @@ async function main() { try { for (const outfile of Object.keys(files)) { const src = files[outfile] + const basename = outfile.replace(/.*\//, "").replace(/\..*/, "") const cjs = outfile.endsWith(".cjs") const mjs = outfile.endsWith(".mjs") + const iife = !cjs && !mjs await esbuild.build({ entryPoints: [src], bundle: true, sourcemap: true, outfile, logLevel: "warning", - external: ["@tensorflow/tfjs", "commander"], + external: iife ? [] : ["@tensorflow/tfjs", "commander"], platform: cjs ? "node" : "browser", target: "es2019", format: mjs ? "esm" : cjs ? "cjs" : "iife", + globalName: iife ? basename : undefined, watch }) } @@ -88,7 +92,7 @@ async function main() { await runTSC(["-b", ".", "pxt", "cli"]) } catch (e) { console.error(e) - } + } } main() diff --git a/cli/src/cli.ts b/cli/src/cli.ts index 505b728..205dfef 100644 --- a/cli/src/cli.ts +++ b/cli/src/cli.ts @@ -11,7 +11,7 @@ import { Options, runModel, sampleModel, testAllModels, testFloatConv, toCSource -} from '../../src/main' +} from '../../src/ml4f' interface CmdOptions { debug?: boolean diff --git a/index.html b/index.html index 1f18959..8bdee05 100644 --- a/index.html +++ b/index.html @@ -7,14 +7,9 @@