This solution builds TensorFlow/JS for Browsers, including individual modules as well as a unified bundle
Included Backends: CPU, WebGL, WebGPU, WASM
Node packages (tfjs-node and tfjs-node-gpu) are not covered
tfjs sourcestf.es2017.js is 3.9MB without wasm and webgpu backends which are another 2MB on toptfjs.esm.js is 2.5MB with wasm and webgpu included
<hr>
npm installgit, bazel, python
Git: assumed to be already installed if you’re here :)bazel 4.x https://docs.bazel.build/versions/4.2.1/install-ubuntu.htmlpython 3.x aliased as python, not compatible with python 2.xDownloads sources and performs full build of all TFJS modules
npm run buildexecutes steps:
scripts/download.sh@tensorflow/tfjs from git into ./src@tensorflow/tfjsscripts/prepare.sh.tfjs-*.ts from build templates.js imports from .json filesscripts/build-wasm.sh.js exports using bazelnode scripts/build-tfjs.js/dist using esbuild with custom resolver plugins and TypeScript compiler settingsAvailable once full build has been completed
npm run buildexecutes steps:
node scripts/build-tfjs.js
build targets in/distusingesbuildwith custom resolver plugins and TypeScript compiler settings
Default typedefs in types/index.d.ts are re-exports of official @tensorflow/* modules
Buildinging typedefs from sources is an experimental feature
npm run typesexecutes steps:
- compile all modules using
TSCtotypes/lib- build rollup using
API-Extractortotypes/tfjs-core.d.tsandtypes/tfjs.d.ts- patch rollup
Remove currently downloaded version of TFJS and reset all cached info
npm run clean
/dist: all JS modules, MAP files and WASM binaries/dist/tfjs.esm.js is default TFJS bundle that includes all available backends/types/index.d.ts re-exports TypeScript type definitions from @tensorflor/tfjs as a single bundlenpm run fast can be used after completed initial build as it executes last build step only
<hr>