-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[js/web] optimize bundle file size (#9817)
* es2017 by default for ort-common * add visualizer and define plugin * es2017 for ort-web. also add build target for es5 * add multiple reduced size build for ort-web * resolve comments, add e2e tests and add docs
- Loading branch information
Showing
18 changed files
with
382 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
/script/ | ||
/test/ | ||
|
||
/dist/**/*.report.html | ||
|
||
/types/**/*.d.ts | ||
!/types/lib/**/*.d.ts | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/naming-convention */ | ||
|
||
/** | ||
* The interface BuildDefinitions contains a set of flags which are defined at build time. | ||
* | ||
* Those flags are processed in terser for tree shaking to remove unused code. | ||
* No flags in this file should present in production build. | ||
*/ | ||
interface BuildDefinitions { | ||
/** | ||
* defines whether to disable the whole WebGL backend in the build. | ||
*/ | ||
DISABLE_WEBGL: boolean; | ||
/** | ||
* defines whether to disable the whole WebAssembly backend in the build. | ||
*/ | ||
DISABLE_WASM: boolean; | ||
/** | ||
* defines whether to disable proxy feature in WebAssembly backend in the build. | ||
*/ | ||
DISABLE_WASM_PROXY: boolean; | ||
/** | ||
* defines whether to disable multi-threading feature in WebAssembly backend in the build. | ||
*/ | ||
DISABLE_WASM_THREAD: boolean; | ||
} | ||
|
||
declare let BUILD_DEFS: BuildDefinitions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports */ | ||
// We use "require" instead of "import" here because import statement must be put in top level. Our current code does | ||
// not allow terser to tree-shaking code as expected because some codes are treated as having side effects. | ||
// So we import code inside the if-clause to allow terser remove the code safely. | ||
|
||
export * from 'onnxruntime-common'; | ||
import {registerBackend} from 'onnxruntime-common'; | ||
import {onnxjsBackend} from './backend-onnxjs'; | ||
import {wasmBackend} from './backend-wasm'; | ||
|
||
registerBackend('webgl', onnxjsBackend, -1); | ||
registerBackend('wasm', wasmBackend, 0); | ||
if (!BUILD_DEFS.DISABLE_WEBGL) { | ||
const onnxjsBackend = require('./backend-onnxjs').onnxjsBackend; | ||
registerBackend('webgl', onnxjsBackend, -1); | ||
} | ||
if (!BUILD_DEFS.DISABLE_WASM) { | ||
const wasmBackend = require('./backend-wasm').wasmBackend; | ||
registerBackend('wasm', wasmBackend, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.