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 f1f8f31
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 42 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
@@ -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,
}
}
}
}
}
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

0 comments on commit f1f8f31

Please sign in to comment.