mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-06-13 01:09:22 +00:00
### Description This PR is a preview of cherry-picks for ort-web to `rel-1.17.3` based on `rel-1.17.2`. <details> <summary>Changes of ort-web to cherry-pick</summary> The following commits are from main branch. `o` stands for pick, and `x` stands for skip. ``` o2e0a388c36[js/webgpu] Add HardSigmoid support (#19215) od226e40856[js/webgpu] set query type in onRunStart (#19202) o61610ff986[js/webgpu] Add FusedConv clip test case (#18900) oa33b5bd1fa[JS/WebGPU] Added Uniforms to SkipLayerNorm. (#18788) o591f90c0b9[js/webgpu] Fix issue of timestamp query (#19258) o7252c6e747[WebNN EP] Support WebNN async API with Asyncify (#19145) o5b06505073[js/webgpu] Fix Tanh explosion (#19201) o656ca66186[js/webgpu] Support uniforms for conv, conv transpose, conv grouped (#18753) oa3f0e2422b[js/webgpu] Support f16 uniform (#19098) o9e69606360fix f16 for attention, enable slice and flatten for more types (#19262) o624b4e2063[js/webgpu] Remove enableShapesUniforms (#19279) o90883a366a[js/webgpu] Add hardSigmoid activation for fusedConv (#19233) o85cef0af8c[js/webgpu] Support capture and replay for jsep (#18989) od73131cf0f[js/webgpu] Use DataType as uniform cpu type (#19281) odd1f6ccc45[js/webgpu] resolve codescan alert (#19343) o3a2ab1963a[js/webgpu] Refactor createTensorShapeVariables (#18883) oefc17e79de[js/webgpu] Fix the undefined push error (#19366) x50806a7dd5[js/web] support external data in npm test (#19377) occbe264a39[js/webgpu] Add LeakyRelu activation for fusedConv (#19369) o5ff27ef02a[js/webgpu] support customop FastGelu (#19392) x03be65e064[js/web] fix types exports in package.json (#19458) o06269a3952[js/webgpu] allow uint8 tensors for webgpu (#19545) odfeda9019c[JS/WebGPU] Add MatMulNBits (#19446) o1b48054e1b[js/webgpu] Create Split indices helpers by rank, not by shape (#19554) o3fe2c137ee[js] small fix to workaround formatter (#19400) x70567a4b3a[js/web] use ApiTensor insteadof onnxjs Tensor in TensorResultValidator (#19358) o6e04e36e3f[js/common] upgrade tsc in common from 4.9.5 to 5.2.2 (#19317) o58f4921686[js] changes to allow Float16Array if any polyfill is available (#19305) o57d6819212[js/web] Fix fused-conv is not included in npm test (#19581) oebd220b073Misspelling in README.md (#19433) o38c3432393Bump ip from 1.1.8 to 1.1.9 in /js/react_native (#19582) ofe82fccf1a[js/webgpu] Fix Conv2DTransposeMatMul f16 compilation failure (#19596) o76a2a487a1Bump ip from 1.1.8 to 1.1.9 in /js/react_native/e2e (#19583) o29b1106033[node] Switch to setImmediate to avoid starving the Node.js event loop (#19610) oae3d73c981[JS/WebGPU] Fix Split and Where to handle corner cases. (#19613) oaec2389ad0[js/webgpu] allows a ProgramInfo's RunData to use zero sized output (#19614) obb43a0f133[js/webgpu] minor fixes to make tinyllama work (#19564) o0edb035808[js/web] fix suite test list for zero sized tensor (#19638) o3cb81cdde2[js/common] move 'env.wasm.trace' to 'env.trace' (#19617) oe30618d055[js/webgpu] use Headless for webgpu test by default (#19702) of06164ef8b[js/web] transfer input buffer back to caller thread (#19677) xa788514027[js/web] dump debug logs for karma for diagnose purpose (#19785) o24b72d2613[JS/WebGPU] Preserve zero size input tensor dims. (#19737) o4538d31a8b[js/webgpu] expose a few properties in WebGPU API (#19857) o53de2d8cb0[js/webgpu] Enable GroupedConvVectorize path (#19791) oed250b88c3[JS/WebGPU] Optimize MatMulNBits (#19852) xe771a763c3[js/test] align web test runner flags with ort.env (#19790) o79e50aeef3[js/web] rewrite backend resolve to allow multiple EPs (#19735) oacb0df2280Fix #19931 broken Get Started link of "ONNX Runtime JavaScript API" page (#19932) ob29849a287[js/common] fix typedoc warnings (#19933) oafdab62f53Bump follow-redirects from 1.15.4 to 1.15.6 in /js/web (#19949) o28ad6c3955Bump follow-redirects from 1.15.4 to 1.15.6 in /js/node (#19951) o7e0d424934accumulate in fp32 for Reduce* (#19868) o4c6a6a37f7[js/webgpu] Fix NAN caused by un-initialized buffer in instance-norm (#19387) o01c7aaf6aa[js/webgpu] allow setting env.webgpu.adapter (#19940) oc45cff60cf[js/webgpu] fix maxpool / fp16 (#19981) ``` </details> <details> <summary>Cherry-pick commandlines</summary> ```sh git cherry-pick2e0a388c36git cherry-pickd226e40856git cherry-pick61610ff986git cherry-picka33b5bd1fagit cherry-pick591f90c0b9git cherry-pick7252c6e747git cherry-pick5b06505073git cherry-pick656ca66186git cherry-picka3f0e2422bgit cherry-pick9e69606360git cherry-pick624b4e2063git cherry-pick90883a366agit cherry-pick85cef0af8c#<<<<< Note: conflicts git cherry-pickd73131cf0fgit cherry-pickdd1f6ccc45git cherry-pick3a2ab1963agit cherry-pickefc17e79degit cherry-pickccbe264a39git cherry-pick5ff27ef02agit cherry-pick06269a3952git cherry-pickdfeda9019cgit cherry-pick1b48054e1bgit cherry-pick3fe2c137eegit cherry-pick6e04e36e3fgit cherry-pick58f4921686git cherry-pick57d6819212git cherry-pickebd220b073git cherry-pick38c3432393git cherry-pickfe82fccf1agit cherry-pick76a2a487a1git cherry-pick29b1106033git cherry-pickae3d73c981git cherry-pickaec2389ad0git cherry-pickbb43a0f133git cherry-pick0edb035808git cherry-pick3cb81cdde2git cherry-picke30618d055git cherry-pickf06164ef8bgit cherry-pick24b72d2613git cherry-pick4538d31a8bgit cherry-pick53de2d8cb0git cherry-picked250b88c3git cherry-pick79e50aeef3git cherry-pickacb0df2280git cherry-pickb29849a287git cherry-pickafdab62f53git cherry-pick28ad6c3955git cherry-pick7e0d424934git cherry-pick4c6a6a37f7git cherry-pick01c7aaf6aagit cherry-pickc45cff60cf``` </details> <details> <summary>Cherry-pick conflicts</summary> -85cef0af8c#18989 this change is for enabling graph capture feature for JSEP, and it is done after ROCM EP enabled graph capture feature. However, the ROCM EP graph capture feature is not cherry-picked in rel-1.17.2. </details> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Jiajia Qin <jiajia.qin@intel.com> Co-authored-by: Xu Xing <xing.xu@intel.com> Co-authored-by: satyajandhyala <satya.k.jandhyala@gmail.com> Co-authored-by: Yang Gu <yang.gu@intel.com> Co-authored-by: Wanming Lin <wanming.lin@intel.com> Co-authored-by: Jiajie Hu <jiajie.hu@intel.com> Co-authored-by: Guenther Schmuelling <guschmue@microsoft.com> Co-authored-by: Matttttt <18152455+martholomew@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Segev Finer <segev208@gmail.com> Co-authored-by: Belem Zhang <belem.zhang@intel.com>
452 lines
15 KiB
TypeScript
452 lines
15 KiB
TypeScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
import * as esbuild from 'esbuild';
|
|
import minimist from 'minimist';
|
|
import * as fs from 'node:fs/promises';
|
|
import * as path from 'node:path';
|
|
|
|
/**
|
|
* @summary Build script for ort-web using esbuild.
|
|
*/
|
|
|
|
const args = minimist(process.argv.slice(2));
|
|
/**
|
|
* --bundle-mode=prod (default)
|
|
* Build multiple ort-web bundles for production.
|
|
*
|
|
* --bundle-mode=dev
|
|
* Build a single ort-web bundle for development, and a test bundle.
|
|
*
|
|
* --bundle-mode=perf
|
|
* Build a single ort-web bundle for performance test, and a test bundle.
|
|
*
|
|
* --bundle-mode=node
|
|
* Build a single ort-web bundle for nodejs.
|
|
*/
|
|
const BUNDLE_MODE: 'prod'|'dev'|'perf'|'node' = args['bundle-mode'] || 'prod';
|
|
|
|
/**
|
|
* --debug
|
|
* Enable debug mode. In this mode, esbuild metafile feature will be enabled. Simple bundle analysis will be printed.
|
|
*
|
|
* --debug=verbose
|
|
* Enable debug mode. In this mode, esbuild metafile feature will be enabled. Detailed bundle analysis will be
|
|
* printed.
|
|
*
|
|
* --debug=save
|
|
* Enable debug mode. In this mode, esbuild metafile feature will be enabled. Full bundle analysis will be saved to a
|
|
* file as JSON.
|
|
*/
|
|
const DEBUG = args.debug; // boolean|'verbose'|'save'
|
|
|
|
const SOURCE_ROOT_FOLDER = path.join(__dirname, '../..'); // <ORT_ROOT>/js/
|
|
const DEFAULT_DEFINE = {
|
|
'BUILD_DEFS.DISABLE_WEBGL': 'false',
|
|
'BUILD_DEFS.DISABLE_WEBGPU': 'false',
|
|
'BUILD_DEFS.DISABLE_WASM': 'false',
|
|
'BUILD_DEFS.DISABLE_WASM_PROXY': 'false',
|
|
'BUILD_DEFS.DISABLE_WASM_THREAD': 'false',
|
|
'BUILD_DEFS.DISABLE_TRAINING': 'true',
|
|
};
|
|
|
|
const COPYRIGHT_HEADER = `/*!
|
|
* ONNX Runtime Web v${require('../package.json').version}
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License.
|
|
*/`;
|
|
|
|
interface OrtBuildOptions {
|
|
isProduction?: boolean;
|
|
isNode?: boolean;
|
|
format: 'iife'|'cjs'|'esm';
|
|
outputBundleName: string;
|
|
define?: Record<string, string>;
|
|
}
|
|
|
|
async function buildBundle(options: esbuild.BuildOptions) {
|
|
const result = await esbuild.build({
|
|
logLevel: DEBUG ? (DEBUG === 'verbose' || DEBUG === 'save' ? 'verbose' : 'debug') : 'info',
|
|
metafile: !!DEBUG,
|
|
absWorkingDir: SOURCE_ROOT_FOLDER,
|
|
bundle: true,
|
|
banner: {js: COPYRIGHT_HEADER},
|
|
...options
|
|
});
|
|
if (DEBUG) {
|
|
if (DEBUG === 'save') {
|
|
await fs.writeFile(
|
|
`${path.basename(options.outfile!)}.esbuild.metafile.json`, JSON.stringify(result.metafile!, null, 2));
|
|
} else {
|
|
console.log(await esbuild.analyzeMetafile(result.metafile!, {verbose: DEBUG === 'verbose'}));
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
async function minifyCode(sourceCode: string): Promise<string> {
|
|
const result = await esbuild.transform(sourceCode, {
|
|
minify: true,
|
|
legalComments: 'none',
|
|
});
|
|
return result.code;
|
|
}
|
|
|
|
async function buildOrt({
|
|
isProduction = false,
|
|
isNode = false,
|
|
format,
|
|
outputBundleName,
|
|
define = DEFAULT_DEFINE,
|
|
}: OrtBuildOptions) {
|
|
// #region Plugin: resolve ignore imports
|
|
|
|
/**
|
|
* This plugin is used to ignore a few nodejs imports that are not used in the browser. Those imported functions are
|
|
* not really used in the browser because they are usually put behind a feature check. However, esbuild does not know
|
|
* that. It will complain about those imports are not available in the browser.
|
|
*
|
|
* This plugin will ignore those imports and replace them with empty exports.
|
|
*/
|
|
const excludeNodejsImports = {
|
|
name: 'exclude-nodejs-imports',
|
|
setup(build: esbuild.PluginBuild) {
|
|
build.onResolve({filter: /(^node:|^worker_threads$|^fs$|^path$|^perf_hooks$|^os$)/}, args => ({
|
|
namespace: 'nodejs-ignore',
|
|
path: args.path,
|
|
sideEffects: false,
|
|
}));
|
|
build.onLoad({filter: /.*/, namespace: 'nodejs-ignore'}, args => {
|
|
switch (args.path) {
|
|
case 'node:fs/promises':
|
|
case 'node:fs':
|
|
case 'fs':
|
|
return {
|
|
contents: 'export const readFile = undefined;' +
|
|
'export const readFileSync = undefined;' +
|
|
'export const createReadStream = undefined;'
|
|
};
|
|
case 'node:os':
|
|
case 'os':
|
|
return {contents: 'export const cpus = undefined;'};
|
|
case 'node:path':
|
|
case 'path':
|
|
return {contents: 'export const join = undefined;'};
|
|
default:
|
|
return {contents: ''};
|
|
}
|
|
});
|
|
},
|
|
};
|
|
// #endregion
|
|
|
|
// #region Plugin: web assembly multi-thread worker loader
|
|
|
|
/**
|
|
* This plugin is used to load web assembly multi-thread worker code as string.
|
|
*
|
|
* This allows to create the worker from a Blob, so we don't need to create a separate file for the worker.
|
|
*/
|
|
const wasmThreadedHandler = {
|
|
name: 'wasm-threaded-handler',
|
|
setup(build: esbuild.PluginBuild) {
|
|
build.onLoad({filter: /[\\/]ort-wasm-threaded\.worker\.js$/}, async args => {
|
|
let contents = await fs.readFile(args.path, {encoding: 'utf-8'});
|
|
if (isProduction) {
|
|
contents = await minifyCode(contents);
|
|
}
|
|
return {loader: 'text', contents};
|
|
});
|
|
},
|
|
};
|
|
// #endregion
|
|
|
|
// #region Plugin: generated emscripten .js loader
|
|
|
|
/**
|
|
* This plugin is used to patch the generated emscripten .js file for multi-thread build.
|
|
*
|
|
* Since we use inline worker for multi-thread, we make an optimization to use function.toString() to get the
|
|
* implementation of the exported `ortWasmThreaded` function to reduce the size of the bundle. However, the generated
|
|
* function uses a variable `_scriptDir` which is defined inside an IIFE closure. When we use function.toString(), the
|
|
* worker code will throw "_scriptDir is not defined" error.
|
|
*
|
|
* To fix this error, we need to patch the generated code to replace access to `_scriptDir` with `typeof _scriptDir
|
|
* !== "undefined" && _scriptDir`.
|
|
*/
|
|
const emscriptenThreadedJsHandler = {
|
|
name: 'emscripten-threaded-js-handler',
|
|
setup(build: esbuild.PluginBuild) {
|
|
build.onLoad({filter: /ort-wasm.*-threaded.*\.js$/}, async args => {
|
|
let contents = await fs.readFile(args.path, {encoding: 'utf-8'});
|
|
// For debug build, Emscripten generates the following code:
|
|
//
|
|
// if (_scriptDir) {
|
|
// scriptDirectory = _scriptDir;
|
|
// }
|
|
//
|
|
// We replace it with:
|
|
//
|
|
// if (typeof _scriptDir !== "undefined" && _scriptDir) {
|
|
// scriptDirectory = _scriptDir;
|
|
// }
|
|
contents = contents.replace('if (_scriptDir) {', 'if (typeof _scriptDir !== "undefined" && _scriptDir) {');
|
|
|
|
// For release build, Emscripten generates the following code:
|
|
//
|
|
// ...,_scriptDir&&(H=_scriptDir),...
|
|
// We replace it with:
|
|
// ...,(typeof _scriptDir !== "undefined" && _scriptDir)&&(H=_scriptDir),...
|
|
contents =
|
|
contents.replace(/_scriptDir(&&\(.+=_scriptDir\))/, '(typeof _scriptDir !== "undefined" && _scriptDir)$1');
|
|
|
|
return {contents};
|
|
});
|
|
}
|
|
};
|
|
// #endregion
|
|
|
|
// #region Plugin: proxy worker loader
|
|
|
|
/**
|
|
* This plugin is used to load proxy worker code as string.
|
|
*/
|
|
const proxyWorkerHandler = {
|
|
name: 'proxy-worker-handler',
|
|
setup(build: esbuild.PluginBuild) {
|
|
build.onResolve(
|
|
{filter: /proxy-worker\/main$/},
|
|
async args => ({path: args.path, namespace: 'proxy-worker', pluginData: args.resolveDir}));
|
|
|
|
build.onLoad({filter: /.*/, namespace: 'proxy-worker'}, async args => {
|
|
const result = await buildBundle({
|
|
entryPoints: [path.resolve(args.pluginData, args.path)],
|
|
outfile: `web/dist/${outputBundleName}.proxy.js`,
|
|
platform: 'browser',
|
|
plugins: [excludeNodejsImports, wasmThreadedHandler, emscriptenThreadedJsHandler],
|
|
define: {
|
|
...build.initialOptions.define,
|
|
'BUILD_DEFS.DISABLE_WASM_PROXY': 'true',
|
|
},
|
|
sourcemap: isProduction ? false : 'inline',
|
|
minify: isProduction,
|
|
write: false,
|
|
});
|
|
|
|
return {loader: 'text', contents: result.outputFiles![0].text};
|
|
});
|
|
},
|
|
};
|
|
// #endregion
|
|
|
|
await buildBundle({
|
|
entryPoints: ['web/lib/index.ts'],
|
|
outfile: `web/dist/${outputBundleName}.js`,
|
|
platform: isNode ? 'node' : 'browser',
|
|
format,
|
|
globalName: 'ort',
|
|
plugins: isNode ? undefined :
|
|
[excludeNodejsImports, proxyWorkerHandler, wasmThreadedHandler, emscriptenThreadedJsHandler],
|
|
external: isNode ? ['onnxruntime-common'] : undefined,
|
|
define,
|
|
sourcemap: isProduction ? 'linked' : 'inline',
|
|
minify: isProduction,
|
|
});
|
|
}
|
|
|
|
async function buildTest() {
|
|
const isProduction = BUNDLE_MODE === 'perf';
|
|
|
|
await buildBundle({
|
|
absWorkingDir: path.join(SOURCE_ROOT_FOLDER, 'web/test'),
|
|
|
|
entryPoints: ['test-main.ts'],
|
|
outfile: isProduction ? 'ort.test.min.js' : 'ort.test.js',
|
|
platform: 'browser',
|
|
format: 'iife',
|
|
define: DEFAULT_DEFINE,
|
|
sourcemap: isProduction ? false : 'inline',
|
|
sourceRoot: path.join(SOURCE_ROOT_FOLDER, 'web/test'),
|
|
external: ['../../node'],
|
|
plugins: [
|
|
// polyfill nodejs modules
|
|
require('esbuild-plugin-polyfill-node').polyfillNode({globals: false}),
|
|
// make "ort" external
|
|
{
|
|
name: 'make-ort-external',
|
|
setup(build: esbuild.PluginBuild) {
|
|
build.onResolve(
|
|
{filter: /^onnxruntime-common$/},
|
|
_args => ({path: 'onnxruntime-common', namespace: 'make-ort-external'}));
|
|
build.onLoad(
|
|
{filter: /.*/, namespace: 'make-ort-external'},
|
|
_args => ({contents: 'module.exports = globalThis.ort;'}));
|
|
}
|
|
}
|
|
],
|
|
minify: isProduction,
|
|
});
|
|
}
|
|
|
|
async function main() {
|
|
// tasks for each esbuild bundle
|
|
const buildTasks: Array<Promise<void>> = [];
|
|
/**
|
|
* add one build task
|
|
*/
|
|
const addBuildTask = async (task: Promise<void>) => {
|
|
if (DEBUG) {
|
|
// in DEBUG mode, build sequentially
|
|
await task;
|
|
} else {
|
|
buildTasks.push(task);
|
|
}
|
|
};
|
|
/**
|
|
* add all 6 build tasks for web bundles. Includes:
|
|
* - IIFE, debug: [name].js
|
|
* - IIFE, production: [name].min.js
|
|
* - CJS, debug: cjs/[name].js
|
|
* - CJS, production: cjs/[name].min.js
|
|
* - ESM, debug: esm/[name].js
|
|
* - ESM, production: esm/[name].min.js
|
|
*/
|
|
const addAllWebBuildTasks = async (options: Omit<OrtBuildOptions, 'format'>) => {
|
|
// [name].js
|
|
await addBuildTask(buildOrt({
|
|
...options,
|
|
format: 'iife',
|
|
}));
|
|
// [name].min.js
|
|
await addBuildTask(buildOrt({
|
|
...options,
|
|
outputBundleName: options.outputBundleName + '.min',
|
|
format: 'iife',
|
|
isProduction: true,
|
|
}));
|
|
// cjs/[name].js
|
|
await addBuildTask(buildOrt({
|
|
...options,
|
|
outputBundleName: 'cjs/' + options.outputBundleName,
|
|
format: 'cjs',
|
|
}));
|
|
// cjs/[name].min.js
|
|
await addBuildTask(buildOrt({
|
|
...options,
|
|
outputBundleName: 'cjs/' + options.outputBundleName + '.min',
|
|
format: 'cjs',
|
|
isProduction: true,
|
|
}));
|
|
// esm/[name].js
|
|
await addBuildTask(buildOrt({
|
|
...options,
|
|
outputBundleName: 'esm/' + options.outputBundleName,
|
|
format: 'esm',
|
|
}));
|
|
// esm/[name].min.js
|
|
await addBuildTask(buildOrt({
|
|
...options,
|
|
outputBundleName: 'esm/' + options.outputBundleName + '.min',
|
|
format: 'esm',
|
|
isProduction: true,
|
|
}));
|
|
};
|
|
|
|
if (BUNDLE_MODE === 'node' || BUNDLE_MODE === 'prod') {
|
|
// ort.node.min.js
|
|
await addBuildTask(buildOrt({
|
|
isProduction: true,
|
|
isNode: true,
|
|
format: 'cjs',
|
|
outputBundleName: 'ort.node.min',
|
|
define: {
|
|
...DEFAULT_DEFINE,
|
|
'BUILD_DEFS.DISABLE_WEBGPU': 'true',
|
|
'BUILD_DEFS.DISABLE_WEBGL': 'true',
|
|
'BUILD_DEFS.DISABLE_WASM_PROXY': 'true',
|
|
'BUILD_DEFS.DISABLE_WASM_THREAD': 'true',
|
|
},
|
|
}));
|
|
}
|
|
|
|
if (BUNDLE_MODE === 'dev') {
|
|
// ort.all.js
|
|
await addBuildTask(buildOrt({outputBundleName: 'ort.all', format: 'iife', define: {...DEFAULT_DEFINE}}));
|
|
}
|
|
|
|
if (BUNDLE_MODE === 'perf') {
|
|
// ort.all.min.js
|
|
await addBuildTask(buildOrt({
|
|
isProduction: true,
|
|
outputBundleName: 'ort.all.min',
|
|
format: 'iife',
|
|
}));
|
|
}
|
|
|
|
if (BUNDLE_MODE === 'prod') {
|
|
// ort.all[.min].js
|
|
await addAllWebBuildTasks({outputBundleName: 'ort.all'});
|
|
|
|
// ort[.min].js
|
|
await addAllWebBuildTasks({
|
|
outputBundleName: 'ort',
|
|
define: {...DEFAULT_DEFINE, 'BUILD_DEFS.DISABLE_WEBGPU': 'true'},
|
|
});
|
|
// ort.webgpu[.min].js
|
|
await addAllWebBuildTasks({
|
|
outputBundleName: 'ort.webgpu',
|
|
define: {...DEFAULT_DEFINE, 'BUILD_DEFS.DISABLE_WEBGL': 'true'},
|
|
});
|
|
// ort.wasm[.min].js
|
|
await addAllWebBuildTasks({
|
|
outputBundleName: 'ort.wasm',
|
|
define: {...DEFAULT_DEFINE, 'BUILD_DEFS.DISABLE_WEBGPU': 'true', 'BUILD_DEFS.DISABLE_WEBGL': 'true'},
|
|
});
|
|
// ort.webgl[.min].js
|
|
await addAllWebBuildTasks({
|
|
outputBundleName: 'ort.webgl',
|
|
define: {
|
|
...DEFAULT_DEFINE,
|
|
'BUILD_DEFS.DISABLE_WEBGPU': 'true',
|
|
'BUILD_DEFS.DISABLE_WASM': 'true',
|
|
},
|
|
});
|
|
// ort.wasm-core[.min].js
|
|
await addAllWebBuildTasks({
|
|
outputBundleName: 'ort.wasm-core',
|
|
define: {
|
|
...DEFAULT_DEFINE,
|
|
'BUILD_DEFS.DISABLE_WEBGPU': 'true',
|
|
'BUILD_DEFS.DISABLE_WEBGL': 'true',
|
|
'BUILD_DEFS.DISABLE_WASM_PROXY': 'true',
|
|
'BUILD_DEFS.DISABLE_WASM_THREAD': 'true',
|
|
},
|
|
});
|
|
// ort.training.wasm[.min].js
|
|
await addAllWebBuildTasks({
|
|
outputBundleName: 'ort.training.wasm',
|
|
define: {
|
|
...DEFAULT_DEFINE,
|
|
'BUILD_DEFS.DISABLE_TRAINING': 'false',
|
|
'BUILD_DEFS.DISABLE_WEBGPU': 'true',
|
|
'BUILD_DEFS.DISABLE_WEBGL': 'true',
|
|
},
|
|
});
|
|
}
|
|
|
|
if (BUNDLE_MODE === 'dev' || BUNDLE_MODE === 'perf') {
|
|
await addBuildTask(buildTest());
|
|
}
|
|
|
|
await Promise.all(buildTasks);
|
|
|
|
if (BUNDLE_MODE === 'prod') {
|
|
// generate package.json files under each of the dist folders for commonJS and ESModule
|
|
// this trick allows typescript to import this package as different module type
|
|
// see also: https://evertpot.com/universal-commonjs-esm-typescript-packages/
|
|
await fs.writeFile(path.resolve(__dirname, '../dist/cjs', 'package.json'), '{"type": "commonjs"}');
|
|
await fs.writeFile(path.resolve(__dirname, '../dist/esm', 'package.json'), '{"type": "module"}');
|
|
}
|
|
}
|
|
|
|
void main();
|