Skip to content

Conversation

@nico-martin
Copy link
Collaborator

No description provided.

@nico-martin nico-martin requested a review from xenova November 27, 2025 06:36
@xenova
Copy link
Collaborator

xenova commented Dec 1, 2025

Amazing -- I will be testing this out in the next few days! 😍

@xenova xenova changed the title added esuild [v4] Switch build system to use esbuild Dec 1, 2025
Copy link
Collaborator

@xenova xenova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Good start 👍

Comment on lines +59 to +62
"esbuild": "^0.27.0",
"onnxruntime-node": "1.24.0-dev.20251104-75d35474d5",
"onnxruntime-web": "1.24.0-dev.20251104-75d35474d5",
"rimraf": "^6.1.2",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be devDependencies

Comment on lines +47 to +84
console.log(`\nBuilding ${regularFile}...`);
await esbuild({
bundle: true,
treeShaking: true,
logLevel: "warning",
entryPoints: [path.join(rootDir, "src/transformers.js")],
platform,
format,
outfile: path.join(outdir, regularFile),
sourcemap: true,
external: externalModules,
plugins,
logOverride: {
// Suppress import.meta warning for CJS builds - it's handled gracefully in the code
"empty-import-meta": "silent",
},
});
reportSize(path.join(outdir, regularFile));

console.log(`\nBuilding ${minFile}...`);
await esbuild({
bundle: true,
treeShaking: true,
logLevel: "warning",
entryPoints: [path.join(rootDir, "src/transformers.js")],
platform,
format,
outfile: path.join(outdir, minFile),
sourcemap: true,
minify: true,
external: externalModules,
plugins,
legalComments: "none",
logOverride: {
// Suppress import.meta warning for CJS builds - it's handled gracefully in the code
"empty-import-meta": "silent",
},
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimize duplication by defining a list of defaults which we unpack unto each config.


try {
console.log("=== CLEAN ===");
execSync(`rimraf ${DIST_FOLDER}`, { stdio: "inherit" });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are going to call rimraf using execSync, we might as well just use native fs functions to clear the dist directory. -1 dependency :)

Comment on lines +3 to +10
export const NODE_EXTERNAL_MODULES = [
"onnxruntime-common",
"onnxruntime-node",
"sharp",
"node:fs",
"node:path",
"node:url",
];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the node:... list may grow in future. Is there a way to specify a pattern like /^node:.*/?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this may only be possible in the section of code where we use it)

Comment on lines +21 to +29
contents: `
const noop = () => {};
const emptyObj = {};
export default emptyObj;
export const Readable = { fromWeb: noop };
export const pipeline = noop;
export const createWriteStream = noop;
export const createReadStream = noop;
`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be added one, or for each module we will ignore? 👀

Comment on lines +18 to +19
const ORT_JSEP_FILE = 'ort-wasm-simd-threaded.jsep.mjs';
const ORT_BUNDLE_FILE = 'ort.bundle.min.mjs';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[WIP] How do we ensure this is bundled with the main library, enabling #1471

}

console.log("=== CLEAN ===");
execSync(`rimraf ${outdir}`, { stdio: "inherit" });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above.

logOverride: {
"empty-import-meta": "silent",
},
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above RE: duplication.

Maybe we can also consolidate dev and build logic to reduce duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants