reorganize tfjs bundle

pull/280/head
Vladimir Mandic 2021-09-14 22:07:13 -04:00
parent 86506b8b8c
commit f492002a3c
5 changed files with 44 additions and 25 deletions

View File

@ -9,8 +9,9 @@
## Changelog ## Changelog
### **HEAD -> main** 2021/09/13 mandic00@live.com ### **HEAD -> main** 2021/09/14 mandic00@live.com
- add platform and backend capabilities detection
- enhanced automated tests - enhanced automated tests
- enable canvas patching for nodejs - enable canvas patching for nodejs
- full ts strict typechecks - full ts strict typechecks

View File

@ -83,6 +83,14 @@
"output": "dist/human.node-wasm.js", "output": "dist/human.node-wasm.js",
"external": ["@tensorflow"] "external": ["@tensorflow"]
}, },
{
"name": "tfjs/browser/version",
"platform": "browser",
"format": "esm",
"input": "tfjs/tf-version.ts",
"output": "dist/tfjs.version.js",
"external": ["fs", "os", "buffer", "util"]
},
{ {
"name": "tfjs/browser/esm/nobundle", "name": "tfjs/browser/esm/nobundle",
"platform": "browser", "platform": "browser",

View File

@ -102,7 +102,7 @@ export async function backendInfo() {
env.webgl.backend = env.backends.includes('webgl'); env.webgl.backend = env.backends.includes('webgl');
if (env.webgl.supported && env.webgl.backend) { if (env.webgl.supported && env.webgl.backend) {
// @ts-ignore getGPGPUContext only exists on WebGL backend // @ts-ignore getGPGPUContext only exists on WebGL backend
const gl = tf.backend().gpgpu !== 'undefined' ? await tf.backend().getGPGPUContext().gl : null; const gl = (tf.backend().gpgpu !== 'undefined') && (tf.backend().getGPGPUContext) ? await tf.backend().getGPGPUContext().gl : null;
if (gl) { if (gl) {
env.webgl.version = gl.getParameter(gl.VERSION); env.webgl.version = gl.getParameter(gl.VERSION);
env.webgl.renderer = gl.getParameter(gl.RENDERER); env.webgl.renderer = gl.getParameter(gl.RENDERER);

View File

@ -3,16 +3,6 @@
* @external * @external
*/ */
// get versions of all packages
import { version as tfjsVersion } from '@tensorflow/tfjs/package.json';
import { version as tfjsCoreVersion } from '@tensorflow/tfjs-core/package.json';
import { version as tfjsDataVersion } from '@tensorflow/tfjs-data/package.json';
import { version as tfjsLayersVersion } from '@tensorflow/tfjs-layers/package.json';
import { version as tfjsConverterVersion } from '@tensorflow/tfjs-converter/package.json';
import { version as tfjsBackendCPUVersion } from '@tensorflow/tfjs-backend-cpu/package.json';
import { version as tfjsBackendWebGLVersion } from '@tensorflow/tfjs-backend-webgl/package.json';
import { version as tfjsBackendWASMVersion } from '@tensorflow/tfjs-backend-wasm/package.json';
// export all from sources // export all from sources
// requires treeShaking:ignore-annotations due to tfjs misconfiguration // requires treeShaking:ignore-annotations due to tfjs misconfiguration
/* /*
@ -25,7 +15,8 @@ export * from '@tensorflow/tfjs-backend-webgl/src/index';
export * from '@tensorflow/tfjs-backend-wasm/src/index'; export * from '@tensorflow/tfjs-backend-wasm/src/index';
*/ */
// export all from build // export all from build individual packages
/*
export * from '@tensorflow/tfjs-core/dist/index.js'; export * from '@tensorflow/tfjs-core/dist/index.js';
export * from '@tensorflow/tfjs-layers/dist/index.js'; export * from '@tensorflow/tfjs-layers/dist/index.js';
export * from '@tensorflow/tfjs-converter/dist/index.js'; export * from '@tensorflow/tfjs-converter/dist/index.js';
@ -33,16 +24,15 @@ export * as data from '@tensorflow/tfjs-data/dist/index.js';
export * from '@tensorflow/tfjs-backend-cpu/dist/index.js'; export * from '@tensorflow/tfjs-backend-cpu/dist/index.js';
export * from '@tensorflow/tfjs-backend-webgl/dist/index.js'; export * from '@tensorflow/tfjs-backend-webgl/dist/index.js';
export * from '@tensorflow/tfjs-backend-wasm/dist/index.js'; export * from '@tensorflow/tfjs-backend-wasm/dist/index.js';
// export * from '@tensorflow/tfjs-backend-webgpu/dist/index.js'; // experimental */
// export versions // export all from build bundle
export const version = { export * from '@tensorflow/tfjs/dist/index.js';
tfjs: tfjsVersion, export * from '@tensorflow/tfjs-backend-webgl/dist/index.js';
'tfjs-core': tfjsCoreVersion, export * from '@tensorflow/tfjs-backend-wasm/dist/index.js';
'tfjs-data': tfjsDataVersion,
'tfjs-layers': tfjsLayersVersion, // add webgpu to bundle, experimental
'tfjs-converter': tfjsConverterVersion, // export * from '@tensorflow/tfjs-backend-webgpu/dist/index.js';
'tfjs-backend-cpu': tfjsBackendCPUVersion,
'tfjs-backend-webgl': tfjsBackendWebGLVersion, // export versions, overrides version object from @tensorflow/tfjs
'tfjs-backend-wasm': tfjsBackendWASMVersion, export { version } from '../dist/tfjs.version.js';
};

20
tfjs/tf-version.ts Normal file
View File

@ -0,0 +1,20 @@
// get versions of all packages
import { version as tfjsVersion } from '@tensorflow/tfjs/package.json';
import { version as tfjsCoreVersion } from '@tensorflow/tfjs-core/package.json';
import { version as tfjsDataVersion } from '@tensorflow/tfjs-data/package.json';
import { version as tfjsLayersVersion } from '@tensorflow/tfjs-layers/package.json';
import { version as tfjsConverterVersion } from '@tensorflow/tfjs-converter/package.json';
import { version as tfjsBackendCPUVersion } from '@tensorflow/tfjs-backend-cpu/package.json';
import { version as tfjsBackendWebGLVersion } from '@tensorflow/tfjs-backend-webgl/package.json';
import { version as tfjsBackendWASMVersion } from '@tensorflow/tfjs-backend-wasm/package.json';
export const version = {
tfjs: tfjsVersion,
'tfjs-core': tfjsCoreVersion,
'tfjs-data': tfjsDataVersion,
'tfjs-layers': tfjsLayersVersion,
'tfjs-converter': tfjsConverterVersion,
'tfjs-backend-cpu': tfjsBackendCPUVersion,
'tfjs-backend-webgl': tfjsBackendWebGLVersion,
'tfjs-backend-wasm': tfjsBackendWASMVersion,
};