Skip to content

Commit

Permalink
Optimise CLI Webpack configuration (#2175)
Browse files Browse the repository at this point in the history
SWC was previously configured to output CJS, which means any imports
would be transpiled to `require`. This means that any dependencies would
also be loaded as CJS, even though an ESM version may be available. By
changing SWC to output ES6 code and not transpiling any imports, Webpack
loads potentially more ESM code which can be better optimised and
tree-shaken.

Below are the old and new file sizes of the examples. For some examples,
this change reduces the file size by 70%.

<details>
<summary>Before this change</summary>

```
272K    ./bip32/dist/bundle.js
344K    ./bip44/dist/bundle.js
312K    ./browserify-plugin/dist/bundle.js
136K    ./browserify/dist/bundle.js
104K    ./client-status/dist/bundle.js
152K    ./cronjobs/dist/bundle.js
156K    ./dialogs/dist/bundle.js
4.0K    ./errors/dist/bundle.js
108K    ./ethereum-provider/dist/bundle.js
1.1M    ./ethers-js/dist/bundle.js
200K    ./get-entropy/dist/bundle.js
104K    ./get-file/dist/bundle.js
152K    ./home-page/dist/bundle.js
164K    ./images/dist/bundle.js
104K    ./json-rpc/dist/bundle.js
152K    ./lifecycle-hooks/dist/bundle.js
108K    ./localization/dist/bundle.js
156K    ./manage-state/dist/bundle.js
4.0K    ./name-lookup/dist/bundle.js
104K    ./network-access/dist/bundle.js
152K    ./notifications/dist/bundle.js
104K    ./rollup-plugin/dist/bundle.js
156K    ./signature-insights/dist/bundle.js
152K    ./transaction-insights/dist/bundle.js
108K    ./wasm/dist/bundle.js
104K    ./webpack-plugin/dist/bundle.js
4.6M    total
```

</details>

<details>
  <summary>After this change</summary>

```
256K    ./bip32/dist/bundle.js
324K    ./bip44/dist/bundle.js
312K    ./browserify-plugin/dist/bundle.js
136K    ./browserify/dist/bundle.js
104K    ./client-status/dist/bundle.js
136K    ./cronjobs/dist/bundle.js
136K    ./dialogs/dist/bundle.js
4.0K    ./errors/dist/bundle.js
108K    ./ethereum-provider/dist/bundle.js
300K    ./ethers-js/dist/bundle.js
176K    ./get-entropy/dist/bundle.js
104K    ./get-file/dist/bundle.js
 36K    ./home-page/dist/bundle.js
152K    ./images/dist/bundle.js
104K    ./json-rpc/dist/bundle.js
 36K    ./lifecycle-hooks/dist/bundle.js
104K    ./localization/dist/bundle.js
104K    ./manage-state/dist/bundle.js
4.0K    ./name-lookup/dist/bundle.js
104K    ./network-access/dist/bundle.js
104K    ./notifications/dist/bundle.js
104K    ./rollup-plugin/dist/bundle.js
 36K    ./signature-insights/dist/bundle.js
 36K    ./transaction-insights/dist/bundle.js
104K    ./wasm/dist/bundle.js
104K    ./webpack-plugin/dist/bundle.js
3.2M    total
```

</details>

---------

Co-authored-by: Frederik Bolding <[email protected]>
  • Loading branch information
Mrtenz and FrederikBolding authored Feb 9, 2024
1 parent 1ec9bf5 commit d844be7
Show file tree
Hide file tree
Showing 27 changed files with 98 additions and 62 deletions.
2 changes: 1 addition & 1 deletion packages/examples/packages/bip32/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "ZjO2/vyI+gsEEsIWrloT+RXRpDiu90IJh8zk/geewkw=",
"shasum": "ALkwbuS0MFVTbJB0zQXPRdDmyis8TAfZayoVY0dDAow=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/bip44/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "JfQKetc6BTHCZdqd2yeKoJZvMG3qq51ATyr1B3A2Ni8=",
"shasum": "ivu8DqblrnqDucyKZQRFKcsT6uc7Vw+DsQJRJgIXn9Y=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "yWT12MR3BSCI14HKXyFQGp6RhG9s1hMgIRZiJCARYkc=",
"shasum": "nJN72lSBRDfROObGpijTtKtZjRSoWSTgbdo6/CScl1I=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/cronjobs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "IiaQ+vlnHF0JYKKVGd4/kMG+T50Dm7lCcrw2sDKftfQ=",
"shasum": "xBvDzo5oiGIbKEVGmzlI39BCzvh/l/nNkkAcOABQqoo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/dialogs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "uaVAErOHm4rPbUun4eo9xOmObQ2I20rF2IX7BRU57LA=",
"shasum": "wFgSmNho6eVxo+nEE2XlWRFVR8tLqKghhh86ozrwmAg=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/errors/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "yHYVhtnHm6SonjnHmOYISrwKrySimS7p+jOISJsIi90=",
"shasum": "sAk9LVkXo2OI3rnOT+3/RToWgk5xT4IfJ0BJiQbbYjw=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "TU/R5DuCBfqVbdyRuyJztDjIYzupiVlijD5xvcuOZiU=",
"shasum": "m4jFP39tZIR1XMosUJ3u8YIfepiI9aRIMna3Hg8RlQQ=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/ethers-js/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "R6jyQ9MImF2Khms/DjvO8McPmjZAeUej2jbY8XOC49s=",
"shasum": "t9CVxyl+WB6UwtynS8zhgA76KWUmQUdGGP+E0Rj+fR0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/get-entropy/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "nB2XTMy/AC2QW5WWk2xL7Ed//hf/4IeSTdDIBtPZgSs=",
"shasum": "BLq144YW0hKG00k8SN3+7F9rKy6hggZVjjx9WkraNEI=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/get-file/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "vX3F2cUxbpH1b7HmBcqpp6h23iUWW7uwHR8lEmmKqL8=",
"shasum": "20Z28B/48X1gTo6V+RSFpx0BNs13lMwD8FE+NiDn18o=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/home-page/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "rVaZdPjQO1y/11Oc54ud6nBId560CQZlUplvgWenQjI=",
"shasum": "rZXPzEYUFk5k8lG85JaR11U4wombdIZ8xM3go7dyhhg=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/images/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "B9CP2TEbrD65sHO4WgdT6etbwwe9HVMG/EZE41Gclmk=",
"shasum": "YRGwMaOJHIRegfuR/LmMR+fs2pOi3Wg31Fh3Y/lOJfk=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "eYnviy8NIYFFoq8LpNKK59QOB+dD43swieNvMTA4Vrc=",
"shasum": "Zul7ybCncDcgpTUpQNx0iTTvy97JNd0TIzM9QpzVROc=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "nK1EKaUCdvw9Wq636V5wqYNtAle6tmuro090rO+YxLI=",
"shasum": "RVmSqvKdYxv4Ws0cCtkepbmXnQ+6Wj0pJ+/NR0WhqiI=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/json-rpc/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "GvvGS+PSG/6uFDd7XBT3ZI7qsG+LE+rBoqOoVmB1Kq4=",
"shasum": "CF4xhZoqnfJt0pjTffWtNKNr8k4YDXh9ZuaszgPvoUU=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "8cgeiYi2GUhPWmOqquWCiadJPTbSLqo5LDUpAKLbUHA=",
"shasum": "tKAO/jlBp3BZubiu2HrD1idkHDIRPh7sAhOw+7htEN4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/localization/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "pmtVK15TtC9vdrx/Tt+m6cipNVWcN4YrgXS4yl5YI3s=",
"shasum": "1ag+BcW+rfL1qTmpnMA+Sd0h57/sZoprFB4qMFXBmPE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/manage-state/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "lqyeAE0sgCDYiga8uhb/2n7P8X2fEy8K32zTiFE2uv0=",
"shasum": "GFuYJnitc0nYDwAD8jhGyCw/Ufc5Ai9RbJbFWpydlFM=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/name-lookup/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "snZ/j7c61yFp0K0b77HAw0cLdQswUuqoJE+nVrrBK/A=",
"shasum": "ATVuf+9AUmlx48Lw3rcMQia6bf4UBg/M1SXL8FdG8t8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "vUmPNRf1Bbf0MFTUDqrTv14PPpLqBnGQBiiEV3liNlI=",
"shasum": "7TGnfMZy7JaBMNhA62f6lmXWojpzMVSuSkxaKqfyPw0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "rXsyOrPqMBib+UpRgLzZbVtWpZdlLxv4ohvaa+WbSvs=",
"shasum": "QxqKMFGyTlsrrf7nDj/JlbQHDIF2l+eO2E5TttzMS64=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "9/UzYulP10qM9PJ5Xc/bCgMEO6u6oX4GEkDzIjOPq/k=",
"shasum": "Rt8Li02ub7KWGSrpOkrf+P+mSZEYyUsLCQAln3LhYB0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "hGq7EXkTWXrWuOOJrrlzshFjsKZZh91z5SOw+pmnYJg=",
"shasum": "s1ibpWtsuA2ku7WoMzpBHBFH+qQ1b2DI7as9fGPjDBY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/wasm/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "ZEfAOxy5Lid72lpfSfNeAY+68Fc3fVB8bNhYYCDLDng=",
"shasum": "eQZoypi/2K6+BnPVvcwOp3I8uwLKzbzLtAahPHVjOY0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Loading

0 comments on commit d844be7

Please sign in to comment.