Skip to content

Instantly share code, notes, and snippets.

@MikelArnaiz
Last active April 13, 2022 15:42
Show Gist options
  • Save MikelArnaiz/40029e50ed2a13d87290dad366f69fc1 to your computer and use it in GitHub Desktop.
Save MikelArnaiz/40029e50ed2a13d87290dad366f69fc1 to your computer and use it in GitHub Desktop.
parse and increase size-limit.json.
const fs = require('fs');
const sizeLimitIncreaseRate = 1.05
const chunkKBThreshold = 5
// Copy & paste data from "ANALYZE=true yarn build:prod" sidebar
const data =
[
"js/vendor1.d65be6d62f367668194a.chunk.js (145.48 KB)",
"js/vendor2.4421506493bc269f1ec0.chunk.js (69.44 KB)",
"js/lotDetails.a999c9385c65d3f453a7.js (24.79 KB)",
"js/vendor3.e47519dac537cacd3752.chunk.js (20.79 KB)",
"js/vendors~fullscreen-gallery.4666707d22a46bee6a36.chunk.js (18.19 KB)",
"js/vendors~bidding-constraint-charge-required-modal~desktop-info-section~highest-bid-offer-block~loadab~c1e90870.38275bc0cb5c05e18e4d.chunk.js (17.62 KB)",
"js/interestsPage.5dac11d934c895e2a81c.js (17.6 KB)",
"js/homepage.6efdcf109ddbea602c87.js (13.98 KB)",
"js/vendors~interestsPage~searchResults.dccae39f4068ca7bb88d.chunk.js (13.75 KB)",
"js/followedAuctions.5126fbc19c0f5aafc40c.js (13.67 KB)",
"js/auctionListPage.0dd9494ee09720f9d981.js (13.37 KB)",
"js/searchResults.e2d5ff63f4615b691947.js (12.73 KB)",
"js/paymentRequests.139cd5bcc2f949cf7a2c.js (11.93 KB)",
"js/category1page.24ceace2661705fea945.js (11.08 KB)",
"js/lotDetails~lotsFromSeller.b8107c0cef3bb992e3b8.chunk.js (10.23 KB)",
"js/payment-methods-container.844b026604e91d440d07.chunk.js (10.08 KB)",
"js/lotsFromSeller.ae4b0a5dc966d1ed735d.js (10.05 KB)",
"js/vendors~auctionListPage~category0page~category1page~homepage~interestsPage~lotDetails~lotsFromSeller~e7ffbc84.28934b446bf8f8782d0e.chunk.js (9.71 KB)",
"js/savedSearches.17f19e1fafe737f44a79.js (9.13 KB)",
"js/expertsGenericPage.4f6037bee349255d79fe.js (9 KB)",
"js/payments.3f3334d30096e2da9802.js (8.65 KB)",
"js/searchResultsOld.2ee65340dab5c16c226d.js (8.25 KB)",
"js/auctionListPage~category0page~category1page~homepage~interestsPage~lotDetails~lotsFromSeller~payment~dcd2f095.fb53f2f59bcf1432bea6.chunk.js (7.73 KB)",
"js/expertsSpecificPage.be1d2fc7db75d24c2e40.js (7.64 KB)",
"js/vendors~lotDetails.0b4f3c982aae89d2be83.chunk.js (7.26 KB)",
"js/auctionListPage~category0page~category1page~homepage~lotsFromSeller~other-interesting-lots~searchLan~6f1930d0.7d8a66af82f97e344018.chunk.js (7.22 KB)",
"js/vendors~lot-bidding-actions.b0dc2206ec47eaadc5df.chunk.js (7.22 KB)",
"js/searchLandingPage.552803bf0f8ddd8d5e34.js (6.93 KB)",
"js/auctionListPage~category0page~category1page~homepage~interestsPage~lotDetails~lotsFromSeller~searchL~33fed479.1b8351942d850e9340dd.chunk.js (6.88 KB)",
"js/lotDetails~payments.b4669050d59d0cf39054.chunk.js (6.75 KB)",
"js/zeroResultsPage~zeroResultsPageOld.4e06bddbe2d1f547a869.chunk.js (6.69 KB)",
"js/category0page~category1page~expertsSpecificPage~homepage.966cd03022de09998df7.chunk.js (6.57 KB)",
"js/bidding-constraint-charge-required-modal.7b0910e3d9830940bd52.chunk.js (6.5 KB)",
"js/lot-bidding-actions.a77423026525bb619281.chunk.js (6.48 KB)",
"js/auctionListPage~category0page~category1page~homepage~interestsPage~lotsFromSeller~other-interesting-~0f1ef6dc.4d110a772b4b5bb9b6d2.chunk.js (6.43 KB)",
"js/searchLandingPage~searchResultsOld.70638bea45d320d064b5.chunk.js (6.34 KB)",
"js/vendors~payment-methods-container.a9109091136efc1a082e.chunk.js (6.14 KB)",
"js/category0page~category1page.f2091c0000c9cc848dc3.chunk.js (5.59 KB)",
"js/lot-bid-status-section.7e0301f7a8385ec6b3c3.chunk.js (5.55 KB)",
"js/paymentRequests~payments.5ef023d84f1ff353e89d.chunk.js (5.52 KB)",
"js/auctionListPage~category0page~category1page~expertsGenericPage~expertsSpecificPage~homepage~interest~ce8e106a.b08b4fbee24054a8425e.chunk.js (5.46 KB)",
"js/vendors~auctionListPage~category0page~category1page~expertsGenericPage~expertsSpecificPage~followedA~5d58eedc.8adafb742dc8bc5fc34a.chunk.js (5.37 KB)",
"js/vendors~paymentRequests.faa2fc3db3651306cdc0.chunk.js (5.26 KB)",
"js/desktop-info-section.284a89bc1aeb9def1562.chunk.js (5.03 KB)",
"js/highest-bid-offer-block.c9b4eb0de20981b76041.chunk.js (4.66 KB)",
"js/mobile-info-section.f2a88644874e4d2c8329.chunk.js (4.5 KB)",
"js/vendors~searchResultsOld.dd042afc4ca5ce773330.chunk.js (4.43 KB)",
"js/vendors~category0page~category1page~homepage.e9355661282b367275f2.chunk.js (4.42 KB)",
"js/vendors~auctionListPage.317edf9e3d73a61ec292.chunk.js (4.41 KB)",
"js/lot-bid-other-costs.f5114e0cd3e80f2f8fc0.chunk.js (4.38 KB)",
"js/zeroResultsPageOld.4dd8cdff90a5eb96c0d5.js (4.32 KB)",
"js/highest-bid-offer-block~lot-bid-history-container~mobile-info-section.7eb3a3764bcc56ed96b0.chunk.js (4.27 KB)",
"js/real-time-channel.6a2015b19bc17ab848da.chunk.js (4.13 KB)",
"js/lot-bid-status.07a24e61f9bfc5fe15ce.chunk.js (4.06 KB)",
"js/vendors~lot-bid-status-section.5384d7cf2a4c85c81880.chunk.js (3.74 KB)",
"js/lot-shipping-info.278522b4f76bae1f655f.chunk.js (3.65 KB)",
"js/orderInvoices.03ca0bb58eb6994ecd5e.js (3.61 KB)",
"js/payment-result.29ffbacc7177f410cc0d.chunk.js (3.53 KB)",
"js/category0page.c9e380b0c66a302e6916.js (3.45 KB)",
"js/lot-expert-estimate-container.f6b0b546000acce69878.chunk.js (3.44 KB)",
"js/loadable-sticky-footer.42645ee0cb55e27bceba.chunk.js (3.3 KB)",
"js/mock-bidding-constraint.302ed44f69db6449d22b.chunk.js (3.17 KB)",
"js/lot-explicit-content-modal.03b09d45860b6dd83b3c.chunk.js (2.96 KB)",
"js/payment-status-success.8ec0abcff00b5a7d8d14.chunk.js (2.93 KB)",
"js/buying-info.c6bc836403444d487478.chunk.js (2.78 KB)",
"js/vendors~auctionListPage~category0page~category1page~expertsSpecificPage~homepage~interestsPage~lotDe~f3b45130.9836e37cd9c67549296d.chunk.js (2.74 KB)",
"js/lot-countdown-container.2a9d198f6de00e0b8c5a.chunk.js (2.47 KB)",
"js/lot-current-bid-container.1c55e7518902de63ca43.chunk.js (2.39 KB)",
"js/lot-bid-preview.055a5e390e461b41e837.chunk.js (2.06 KB)",
"js/payment-received.23ab2f43dc4b2c8ae6b2.chunk.js (1.91 KB)",
"js/lot-social-share.0194b0b53abdb1e1c432.chunk.js (1.77 KB)",
"js/lot-bidding-block.5629bb53b437e32d8715.chunk.js (1.64 KB)",
"js/zeroResultsPage.aa82034400c770f2fcdc.js (1.63 KB)",
"js/common.b174797d1bf754c8a820.js (1.39 KB)",
"js/fullscreen-gallery.2ebb078c65d364a28d9d.chunk.js (1.33 KB)",
"js/other-interesting-lots.615ad7a856df08e1ea55.chunk.js (1.1 KB)",
"js/loadable-lot-contacts.00e92e01e110497436d4.chunk.js (840 B)",
"js/registration-modal.d3e1516ed02ac7f08e68.chunk.js (734 B)",
"js/lot-bid-modal.3d85a9c93d79164a6132.chunk.js (729 B)",
"js/lot-bid-history-container.9530f0eb82b349a8a027.chunk.js (589 B)",
"js/lot-experts-summary.2e5ad5ee13fa2d32b6e5.chunk.js (571 B)",
"js/extra-guarantee-success-modal.44804137cf0f1b15ec5e.chunk.js (535 B)",
"js/description-modal.4a45966e5bfb879d291c.chunk.js (454 B)",
"js/lot-closed-overlay.86beebce3bfbca60be6f.chunk.js (430 B)",
"js/lot-bid-submit-status.a0d3814859b6d0203434.chunk.js (429 B)",
"js/bidding-constraint-pending-payment-modal.5a09d307a128892e86d8.chunk.js (417 B)",
"js/lot-bidding-block-guarantee-required.3a5a320d552e9113eb8d.chunk.js (343 B)",
"js/lot-bidding-block-not-allowed.7568c10e989377cde32f.chunk.js (309 B)",
"js/lot-context.791003d2bbb8f73fa19c.chunk.js (286 B)",
"js/bidding-constraint-try-again-modal.47312a2bf46d28430ac4.chunk.js (280 B)"
]
.map((entry, index) => {
try {
// https://regex101.com/r/31NfzC/1
const RE = /^js\/(?:(?<chunk2>[\w\-\~]+)\~[a-f0-9]+\.|(?<chunk>[\w\-\~]+\.))(?<hash>[a-f0-9]+)(?:\.chunk)?\.js \((?<size>\d+(?:\.\d+)?) (?<unit>K?B)\)$/
const { chunk2, chunk, size, unit } = RE.exec(entry).groups
const filename = chunk || chunk2
const parsedSize = parseFloat(size, 10)
const sizeInKB = unit === 'B' ? parsedSize / 1024 : parsedSize
return {
path: `./public/assets/buyer/ui/v2/webpack/js/${filename}*.js`,
// prevLimit: `${size}${unit}`,
limit: `${sizeInKB < chunkKBThreshold ? Math.ceil(sizeInKB).toFixed(0) : (sizeInKB * sizeLimitIncreaseRate).toFixed(1) }kb`
}
} catch (err) {
console.error(err)
throw new Error(`Error parsing entry ${index} with input ${entry}`)
}
})
.sort((a, b) => a.path.localeCompare(b.path))
fs.writeFileSync('.size-limit.json', JSON.stringify(data, null, 2));
console.log(JSON.stringify(data, null, 2))
console.log("Done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment