tslib was formerly included by chance since typescript depends on it. With this change, we explicitly depend on it and add it as a dependency to the tfjs_bundle Bazel rule. Rollup uses the es5 downleveling plugin, which uses tslib for bundle size optimization.
Create tools/make_rollup_config.ts, which exports a function to create a tfjs rollup configuration. The only thing tools/rollup_template.config.js does now is import and call that function.
Move the custom es5 downleveling plugin to its own file.
Co-authored-by: Na Li <linazhao@google.com>
BUG
* Allow bundles to keep 'require' calls as 'require' calls
@rollup/plugin-commonjs rewrites 'require' calls to 'import' statements, but this is not always desirable. This commit adds the 'leave_as_require' option to 'tfjs_bundle', which allows specifying a list of modules to leave as 'require' calls.
This commit also disables @rollup/plugin-commonjs when targeting commonjs, since require calls do not need to be transpiled for commonjs.
* Always use the commonjs plugin
It is required even for node cjs bundles because we still want to bundle the commonjs modules. Without the plugin, they're left as 'require()' calls, but with the plugin, their contents are included in the bundle.
* Hook up the "external" parameter of tfjs_bundle rule with rollup_bundle, and add "globals" parameter to tfjs_bundle
* fix lint error
* fix
* fix
* fix
This PR builds tfjs-core and tfjs-backend-cpu using Bazel and makes the build outputs available to the other packages in the monorepo. It also sets up Bazel rules and macros that facilitate converting other packages in the monorepo to Bazel. For more details, see #5133.