Skip to content

Commit cb59ac3

Browse files
committed
[build] Update package.json and tsup.config.ts for build optimizations
- Added "sideEffects": false to package.json to improve tree-shaking. - Modified tsup.config.ts to enable bundling and splitting for Common.js, while disabling them for ESM output. - Refactored mixin application in Aptos class to ensure mixins are only applied once, improving performance and maintainability.
1 parent e2a2644 commit cb59ac3

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"dist",
3333
"src"
3434
],
35+
"sideEffects": false,
3536
"scripts": {
3637
"build:clean": "rm -rf dist",
3738
"build": "pnpm build:clean && tsup",

src/api/aptos.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ export class Aptos {
8888
* runExample().catch(console.error);
8989
* ```
9090
* @group Client
91-
*/
91+
*/
9292
constructor(config?: AptosConfig) {
93+
ensureMixinsApplied();
9394
this.config = config ?? new AptosConfig();
9495
this.account = new Account(this.config);
9596
this.abstraction = new AccountAbstraction(this.config);
@@ -155,17 +156,27 @@ function applyMixin(targetClass: any, baseClass: any, baseClassProp: string) {
155156
});
156157
}
157158

158-
applyMixin(Aptos, Account, "account");
159-
applyMixin(Aptos, AccountAbstraction, "abstraction");
160-
applyMixin(Aptos, ANS, "ans");
161-
applyMixin(Aptos, Coin, "coin");
162-
applyMixin(Aptos, DigitalAsset, "digitalAsset");
163-
applyMixin(Aptos, Event, "event");
164-
applyMixin(Aptos, Faucet, "faucet");
165-
applyMixin(Aptos, FungibleAsset, "fungibleAsset");
166-
applyMixin(Aptos, General, "general");
167-
applyMixin(Aptos, Staking, "staking");
168-
applyMixin(Aptos, Transaction, "transaction");
169-
applyMixin(Aptos, Table, "table");
170-
applyMixin(Aptos, Keyless, "keyless");
171-
applyMixin(Aptos, AptosObject, "object");
159+
let mixinsApplied = false;
160+
161+
function ensureMixinsApplied() {
162+
if (mixinsApplied) {
163+
return;
164+
}
165+
166+
applyMixin(Aptos, Account, "account");
167+
applyMixin(Aptos, AccountAbstraction, "abstraction");
168+
applyMixin(Aptos, ANS, "ans");
169+
applyMixin(Aptos, Coin, "coin");
170+
applyMixin(Aptos, DigitalAsset, "digitalAsset");
171+
applyMixin(Aptos, Event, "event");
172+
applyMixin(Aptos, Faucet, "faucet");
173+
applyMixin(Aptos, FungibleAsset, "fungibleAsset");
174+
applyMixin(Aptos, General, "general");
175+
applyMixin(Aptos, Staking, "staking");
176+
applyMixin(Aptos, Transaction, "transaction");
177+
applyMixin(Aptos, Table, "table");
178+
applyMixin(Aptos, Keyless, "keyless");
179+
applyMixin(Aptos, AptosObject, "object");
180+
181+
mixinsApplied = true;
182+
}

tsup.config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@ type MandatoryOptions = Options & {
99

1010
// Default config, used as a base template
1111
const DEFAULT_CONFIG: Options = {
12-
bundle: true,
1312
clean: true, // clean up the dist folder
1413
dts: true, // generate dts files
1514
minify: true,
16-
entry: ["src/index.ts"], // include all files under src
1715
skipNodeModulesBundle: true,
1816
sourcemap: true,
19-
splitting: true,
2017
target: "es2020",
2118
platform: "node",
2219
env: {
@@ -31,8 +28,10 @@ const DEFAULT_CONFIG: Options = {
3128
// Common.js config
3229
const COMMON_CONFIG: MandatoryOptions = {
3330
...DEFAULT_CONFIG,
31+
bundle: true,
3432
entry: ["src/index.ts", "src/cli/index.ts"],
3533
format: "cjs",
34+
splitting: true,
3635
outDir: "dist/common",
3736
};
3837

@@ -41,6 +40,11 @@ const ESM_CONFIG: MandatoryOptions = {
4140
...DEFAULT_CONFIG,
4241
entry: ["src/**/*.ts"],
4342
format: "esm",
43+
bundle: false,
44+
splitting: false,
45+
outExtension: () => ({
46+
js: ".mjs",
47+
}),
4448
outDir: "dist/esm",
4549
};
4650

0 commit comments

Comments
 (0)