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 install
git
, 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.x
Downloads sources and performs full build of all TFJS modules
npm run build
executes steps:
scripts/download.sh
@tensorflow/tfjs
from git into ./src
@tensorflow/tfjs
scripts/prepare.sh
.tfjs-*.ts
from build templates.js
imports from .json
filesscripts/build-wasm.sh
.js
exports using bazel
node scripts/build-tfjs.js
/dist
using esbuild
with custom resolver plugins and TypeScript compiler settingsAvailable once full build has been completed
npm run build
executes steps:
node scripts/build-tfjs.js
build targets in/dist
usingesbuild
with 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 types
executes steps:
- compile all modules using
TSC
totypes/lib
- build rollup using
API-Extractor
totypes/tfjs-core.d.ts
andtypes/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>