Skip to content

Commit

Permalink
Default chunk limit of 5, env variable to customize (#1209)
Browse files Browse the repository at this point in the history
  • Loading branch information
bookernath committed Aug 2, 2024
1 parent d1cf327 commit ef2f3cb
Show file tree
Hide file tree
Showing 4 changed files with 368 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-forks-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Limit number of chunks in webpack, customizable via env
13 changes: 12 additions & 1 deletion core/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const nextConfig = {
ignoreDuringBuilds: !!process.env.CI,
dirs: ['app', 'client', 'components', 'lib', 'middlewares'],
},
webpack: (config) => {
webpack: (config, { isServer }) => {
if (process.env.NODE_V8_COVERAGE) {
Object.defineProperty(config, 'devtool', {
get() {
Expand All @@ -28,6 +28,17 @@ const nextConfig = {
});
}

// Limit the number of chunks to reduce CDN requests, which contribute to Edge Request costs
if (!isServer) {
config.plugins.push(
new (require('webpack').optimize.LimitChunkCountPlugin)({
maxChunks: process.env.WEBPACK_MAX_CHUNKS
? parseInt(process.env.WEBPACK_MAX_CHUNKS, 10)
: 5,
}),
);
}

return config;
},
// default URL generation in BigCommerce uses trailing slash
Expand Down
1 change: 1 addition & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"sharp": "^0.33.4",
"tailwind-merge": "^2.4.0",
"tailwindcss-radix": "^3.0.3",
"webpack": "^5.93.0",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit ef2f3cb

Please sign in to comment.