Skip to content

Commit

Permalink
Make tfjs-tfdf work with bundlers (#7054)
Browse files Browse the repository at this point in the history
Set the ESM entrypoint to the flat ESM bundle. Set the cjs entrypoint to the node (cjs) bundle.

Prevent node-specific 'require's in the emscripten bundle from being hoisted to the top of the file. Now, it checks if it's running in node before requiring node-specific things like 'fs' or 'path'.
  • Loading branch information
mattsoulanille authored Nov 17, 2022
1 parent 8fae9c5 commit bf84b79
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 5 additions & 3 deletions tfjs-tfdf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ tfjs_bundle(
"@tensorflow/tfjs-converter",
"path",
"fs",
"jszip",
],
globals = {
"@tensorflow/tfjs-converter": "tf",
"@tensorflow/tfjs-core": "tf",
"jszip": "JSZip",
},
leave_as_require = [
"path",
"fs",
"crypto",
],
umd_name = "tfdf",
deps = [
"//tfjs-tfdf/src:tfdf_web_api_client_js",
Expand Down Expand Up @@ -92,7 +95,6 @@ pkg_npm(
":copy_bundles",
":copy_src_to_dist",
":copy_wasm_files",
"//tfjs-tfdf/wasm:wasm_files",
],
)

Expand Down
8 changes: 7 additions & 1 deletion tfjs-tfdf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
"version": "0.0.1",
"description": "TensorFlow Decision Forests support for TensorFlow.js",
"main": "dist/tf-tfdf.node.js",
"module": "dist/index.js",
"module": "dist/tf-tfdf.fesm.js",
"jsdelivr": "dist/tf-tfdf.min.js",
"unpkg": "dist/tf-tfdf.min.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/tf-tfdf.fesm.js",
"require": "./dist/tf-tfdf.node.js"
}
},
"repository": {
"type": "git",
"url": "https://github.com/tensorflow/tfjs.git",
Expand Down

0 comments on commit bf84b79

Please sign in to comment.