Skip to content

Commit

Permalink
feat(core): Add build target for jsaction contract binary. (#55319)
Browse files Browse the repository at this point in the history
Right now this binary sits at 9.5kb. Additional changes to the library will
be done to reduce the binary size, such as converting event_type from
an enum to an object, and other code size reductions.

PR Close #55319
  • Loading branch information
iteriani authored and pkozlowski-opensource committed Apr 16, 2024
1 parent 7d5bc1c commit bce5e23
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/core/primitives/event-dispatch/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
load("//tools:defaults.bzl", "ts_library", "tsec_test")
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
load("@npm//@bazel/terser:index.bzl", "terser_minified")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -26,3 +28,16 @@ filegroup(
]),
visibility = ["//visibility:public"],
)

rollup_bundle(
name = "bundled_contract_binary_tmp",
entry_point = ":contract_binary.ts",
format = "esm",
deps = [":event-dispatch"],
)

terser_minified(
name = "bundle",
src = ":bundled_contract_binary_tmp",
config_file = ":terser.config.json",
)
12 changes: 12 additions & 0 deletions packages/core/primitives/event-dispatch/contract_binary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/


import {bootstrapEventContract} from './src/register_events';

(window as any)['__jsaction_bootstrap'] = bootstrapEventContract;
20 changes: 20 additions & 0 deletions packages/core/primitives/event-dispatch/terser.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"ecma": "es2020",
"compress": {
"toplevel": true,
"passes": 2,
"pure_getters": true
},
"mangle": {
"toplevel": true,
"properties": true,
"keep_classnames": false,
"keep_fnames": false
},
"format": {
"ecma": "es2020",
"ascii_only": true,
"wrap_func_args": false,
"comments": false
}
}

0 comments on commit bce5e23

Please sign in to comment.