Skip to content

Commit

Permalink
fix: maxInitialRequests should exists in cache groups
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng committed Aug 9, 2024
1 parent 6f19caa commit 1f73922
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 51 deletions.
2 changes: 2 additions & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,8 @@ export interface RawCacheGroupOptions {
maxSize?: number | RawSplitChunkSizes
maxAsyncSize?: number | RawSplitChunkSizes
maxInitialSize?: number | RawSplitChunkSizes
maxAsyncRequests?: number
maxInitialRequests?: number
name?: string | false | Function
reuseExistingChunk?: boolean
enforce?: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ pub struct RawCacheGroupOptions {
pub max_size: Option<Either<f64, RawSplitChunkSizes>>,
pub max_async_size: Option<Either<f64, RawSplitChunkSizes>>,
pub max_initial_size: Option<Either<f64, RawSplitChunkSizes>>,
pub max_async_requests: Option<u32>,
pub max_initial_requests: Option<u32>,
#[napi(ts_type = "string | false | Function")]
#[derivative(Debug = "ignore")]
pub name: Option<RawChunkOptionName>,
Expand Down Expand Up @@ -214,10 +216,8 @@ impl From<RawSplitChunksOptions> for rspack_plugin_split_chunks::PluginOptions {
.unwrap_or(overall_automatic_name_delimiter.clone()),
filename: v.filename.map(Filename::from),
reuse_existing_chunk: v.reuse_existing_chunk.unwrap_or(false),
// TODO(hyf0): the non-enforced default value should be 30
// I would set align default value with Webpack when the options is exposed to users
max_async_requests: u32::MAX,
max_initial_requests: u32::MAX,
max_async_requests: v.max_async_requests.unwrap_or(u32::MAX),
max_initial_requests: v.max_initial_requests.unwrap_or(u32::MAX),
max_async_size,
max_initial_size,
r#type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ Object {
"unknown",
],
"hidePathInfo": false,
"maxAsyncRequests": Infinity,
"maxInitialRequests": Infinity,
"maxAsyncRequests": 4294967295,
"maxInitialRequests": 4294967295,
"minChunks": 1,
"minSize": 10000,
"usedExports": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
it("should not split chunk when maxInitialRequests set to only 1", function () {
const a = require("./node_modules/a");
expect(a).toBe("a");
const b = require("./node_modules/b");
expect(b).toBe("b");
const c = require("./node_modules/c");
expect(c).toBe("c");
const d = require("./node_modules/d");
expect(d).toBe("d");

const fs = require('fs')
const files = fs.readdirSync(__dirname)
expect(files.filter(file => file.endsWith('.js')).length).toBe(1)
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
optimization: {
chunkIds: 'named',
splitChunks: {
maxInitialRequests: 10,
cacheGroups: {
vendors: {
chunks: 'all',
test: /node_modules/,
minSize: 0,
filename: 'split-[name].js',

// should override the splitChunks.maxInitialRequests
maxInitialRequests: 1,
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module.exports = {
+ "sideEffects": true,
@@ ... @@
- "hidePathInfo": false,
- "maxAsyncRequests": Infinity,
- "maxInitialRequests": Infinity,
- "maxAsyncRequests": 4294967295,
- "maxInitialRequests": 4294967295,
+ "hidePathInfo": true,
+ "maxAsyncRequests": 30,
+ "maxInitialRequests": 30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module.exports = {
+ "sideEffects": true,
@@ ... @@
- "hidePathInfo": false,
- "maxAsyncRequests": Infinity,
- "maxInitialRequests": Infinity,
- "maxAsyncRequests": 4294967295,
- "maxInitialRequests": 4294967295,
+ "hidePathInfo": true,
+ "maxAsyncRequests": 30,
+ "maxInitialRequests": 30,
Expand Down
108 changes: 78 additions & 30 deletions packages/rspack/etc/api.md

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions packages/rspack/src/config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,12 +950,8 @@ const applyOptimizationDefaults = (
F(splitChunks, "minSize", () => (production ? 20000 : 10000));
// F(splitChunks, "minRemainingSize", () => (development ? 0 : undefined));
// F(splitChunks, "enforceSizeThreshold", () => (production ? 50000 : 30000));
F(splitChunks, "maxAsyncRequests", () =>
production ? 30 : Number.POSITIVE_INFINITY
);
F(splitChunks, "maxInitialRequests", () =>
production ? 30 : Number.POSITIVE_INFINITY
);
F(splitChunks, "maxAsyncRequests", () => (production ? 30 : 2 ** 32 - 1));
F(splitChunks, "maxInitialRequests", () => (production ? 30 : 2 ** 32 - 1));
D(splitChunks, "automaticNameDelimiter", "-");
const { cacheGroups } = splitChunks;
if (cacheGroups) {
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/src/config/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,8 @@ const sharedOptimizationSplitChunksCacheGroup = {
maxSize: optimizationSplitChunksSizes.optional(),
maxAsyncSize: optimizationSplitChunksSizes.optional(),
maxInitialSize: optimizationSplitChunksSizes.optional(),
maxAsyncRequests: z.number().optional(),
maxInitialRequests: z.number().optional(),
automaticNameDelimiter: z.string().optional()
};
const optimizationSplitChunksCacheGroup = z.strictObject({
Expand Down Expand Up @@ -1272,8 +1274,6 @@ const optimizationSplitChunksOptions = z.strictObject({
cacheGroups: z
.record(z.literal(false).or(optimizationSplitChunksCacheGroup))
.optional(),
maxAsyncRequests: z.number().optional(),
maxInitialRequests: z.number().optional(),
fallbackCacheGroup: z
.strictObject({
chunks: optimizationSplitChunksChunks.optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,11 @@ runtime modules 2.59 KiB 3 modules
./a.js 18 bytes [built] [code generated]
Rspack x.x.x compiled successfully in X.23
asset b-runtime~main-eb1e55e9714495b68bff.js 4.39 KiB [emitted] [immutable] (name: runtime~main)
asset b-runtime~main-2a432c6b45b448fcde80.js 4.39 KiB [emitted] [immutable] (name: runtime~main)
asset b-all-b_js-468c0f551eefc9f96f0b.js 461 bytes [emitted] [immutable] (id hint: all)
asset b-main-72ac2a7c5326395bcc89.js 420 bytes [emitted] [immutable] (name: main)
asset b-main-236b715ba81f9430f0c7.js 420 bytes [emitted] [immutable] (name: main)
asset b-vendors-node_modules_vendor_js-97d43f84c65cc0e25938.js 173 bytes [emitted] [immutable] (id hint: vendors)
Entrypoint main 5.42 KiB = b-runtime~main-eb1e55e9714495b68bff.js 4.39 KiB b-vendors-node_modules_vendor_js-97d43f84c65cc0e25938.js 173 bytes b-all-b_js-468c0f551eefc9f96f0b.js 461 bytes b-main-72ac2a7c5326395bcc89.js 420 bytes
Entrypoint main 5.42 KiB = b-runtime~main-2a432c6b45b448fcde80.js 4.39 KiB b-vendors-node_modules_vendor_js-97d43f84c65cc0e25938.js 173 bytes b-all-b_js-468c0f551eefc9f96f0b.js 461 bytes b-main-236b715ba81f9430f0c7.js 420 bytes
runtime modules 3.17 KiB 5 modules
cacheable modules 40 bytes
./b.js 17 bytes [built] [code generated]
Expand Down

0 comments on commit 1f73922

Please sign in to comment.