Skip to content

Commit

Permalink
feat: align chunkIds default value with webpack (#4822)
Browse files Browse the repository at this point in the history
  • Loading branch information
hardfist authored and ahabhgk committed Jan 2, 2024
1 parent b65f101 commit d7d87e6
Show file tree
Hide file tree
Showing 9 changed files with 628 additions and 613 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ module.exports = {
}
]
},
optimization: {
chunkIds: "named"
},
output: { clean: true },

experiments: {
incrementalRebuild: {
emitAsset: true
Expand Down
6 changes: 5 additions & 1 deletion packages/rspack/src/config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,11 @@ const applyOptimizationDefaults = (
if (production) return "deterministic";
return "named";
});
F(optimization, "chunkIds", (): "named" | "deterministic" => "named");
F(optimization, "chunkIds", (): "named" | "deterministic" => {
if (production) return "deterministic";
if (development) return "named";
return "named"; // we have not implemented 'natural' so use 'named' now
});
F(optimization, "sideEffects", () => (production ? true : "flag"));
D(optimization, "mangleExports", production);
D(optimization, "providedExports", true);
Expand Down
4 changes: 4 additions & 0 deletions packages/rspack/tests/Defaults.unittest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ describe("snapshots", () => {
- "mode": "none",
+ "mode": undefined,
@@ ... @@
- "chunkIds": "named",
- "innerGraph": false,
- "mangleExports": false,
+ "chunkIds": "deterministic",
+ "innerGraph": true,
+ "mangleExports": true,
@@ ... @@
Expand Down Expand Up @@ -156,8 +158,10 @@ describe("snapshots", () => {
- "mode": "none",
+ "mode": "production",
@@ ... @@
- "chunkIds": "named",
- "innerGraph": false,
- "mangleExports": false,
+ "chunkIds": "deterministic",
+ "innerGraph": true,
+ "mangleExports": true,
@@ ... @@
Expand Down
18 changes: 9 additions & 9 deletions packages/rspack/tests/Stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ describe("Stats", () => {
expect(stats?.toJson(statsOptions)).toMatchSnapshot();
expect(stats?.toString(statsOptions)).toMatchInlineSnapshot(`
"PublicPath: auto
asset main.js 211 bytes {main} [emitted] (name: main)
asset main.js 211 bytes {909} [emitted] (name: main)
Entrypoint main 211 bytes = main.js
chunk {main} main.js (main) [entry]
./fixtures/a.js [585] {main}
chunk {909} main.js (main) [entry]
./fixtures/a.js [585] {909}
entry ./fixtures/a
./fixtures/a.js [585] {main}
./fixtures/a.js [585] {909}
entry ./fixtures/a
Rspack compiled successfully (a62f45ec3d75aa689fa1)"
Rspack compiled successfully (57e46af248a1c1fe076f)"
`);
});

Expand Down Expand Up @@ -82,7 +82,7 @@ describe("Stats", () => {
help:
You may need an appropriate loader to handle this file type.
Rspack compiled with 1 error (79a430f2fdbcdc199916)"
Rspack compiled with 1 error (d26fd8b8f7a3bc36f9b5)"
`);
});

Expand Down Expand Up @@ -353,9 +353,9 @@ describe("Stats", () => {
};
expect(stats?.toJson(options)).toMatchSnapshot();
expect(stats?.toString(options).replace(/\\/g, "/")).toMatchInlineSnapshot(`
"asset main.js 211 bytes {main} [emitted] (name: main)
chunk {main} main.js (main) [entry]
./fixtures/a.js [585] {main}"
"asset main.js 211 bytes {909} [emitted] (name: main)
chunk {909} main.js (main) [entry]
./fixtures/a.js [585] {909}"
`);
});

Expand Down
46 changes: 23 additions & 23 deletions packages/rspack/tests/__snapshots__/Stats.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports[`Stats should have ids when ids is true 1`] = `
"main",
],
"chunks": [
"main",
"909",
],
"emitted": true,
"info": {
Expand All @@ -32,7 +32,7 @@ exports[`Stats should have ids when ids is true 1`] = `
"files": [
"main.js",
],
"id": "main",
"id": "909",
"initial": true,
"names": [
"main",
Expand All @@ -45,7 +45,7 @@ exports[`Stats should have ids when ids is true 1`] = `
"modules": [
{
"chunks": [
"main",
"909",
],
"id": "585",
"identifier": "<PROJECT_ROOT>/tests/fixtures/a.js",
Expand All @@ -71,7 +71,7 @@ exports[`Stats should have stats 1`] = `
"main",
],
"chunks": [
"main",
"909",
],
"emitted": true,
"info": {
Expand All @@ -97,13 +97,13 @@ exports[`Stats should have stats 1`] = `
"files": [
"main.js",
],
"id": "main",
"id": "909",
"initial": true,
"modules": [
{
"assets": [],
"chunks": [
"main",
"909",
],
"id": "585",
"identifier": "<PROJECT_ROOT>/tests/fixtures/a.js",
Expand Down Expand Up @@ -150,21 +150,21 @@ exports[`Stats should have stats 1`] = `
],
"assetsSize": 211,
"chunks": [
"main",
"909",
],
"name": "main",
},
},
"errors": [],
"errorsCount": 0,
"filteredModules": undefined,
"hash": "a62f45ec3d75aa689fa1",
"hash": "57e46af248a1c1fe076f",
"logging": {},
"modules": [
{
"assets": [],
"chunks": [
"main",
"909",
],
"id": "585",
"identifier": "<PROJECT_ROOT>/tests/fixtures/a.js",
Expand Down Expand Up @@ -202,7 +202,7 @@ exports[`Stats should have stats 1`] = `
],
"assetsSize": 211,
"chunks": [
"main",
"909",
],
"name": "main",
},
Expand All @@ -222,7 +222,7 @@ exports[`Stats should output stats with query 1`] = `
"main",
],
"chunks": [
"main",
"909",
],
"emitted": true,
"info": {
Expand All @@ -248,13 +248,13 @@ exports[`Stats should output stats with query 1`] = `
"files": [
"main.js",
],
"id": "main",
"id": "909",
"initial": true,
"modules": [
{
"assets": [],
"chunks": [
"main",
"909",
],
"id": "585",
"identifier": "<PROJECT_ROOT>/tests/fixtures/a.js",
Expand Down Expand Up @@ -295,7 +295,7 @@ exports[`Stats should output stats with query 1`] = `
{
"assets": [],
"chunks": [
"main",
"909",
],
"id": "958",
"identifier": "<PROJECT_ROOT>/tests/fixtures/a.js?a=1",
Expand Down Expand Up @@ -331,7 +331,7 @@ exports[`Stats should output stats with query 1`] = `
{
"assets": [],
"chunks": [
"main",
"909",
],
"id": "432",
"identifier": "<PROJECT_ROOT>/tests/fixtures/c.js?c=3",
Expand Down Expand Up @@ -368,7 +368,7 @@ exports[`Stats should output stats with query 1`] = `
{
"assets": [],
"chunks": [
"main",
"909",
],
"id": "919",
"identifier": "<PROJECT_ROOT>/tests/fixtures/abc-query.js",
Expand Down Expand Up @@ -415,21 +415,21 @@ exports.c = require("./c?c=3");
],
"assetsSize": 386,
"chunks": [
"main",
"909",
],
"name": "main",
},
},
"errors": [],
"errorsCount": 0,
"filteredModules": undefined,
"hash": "17fb2a59facde9aafd96",
"hash": "863c8adf2d7c24d82182",
"logging": {},
"modules": [
{
"assets": [],
"chunks": [
"main",
"909",
],
"id": "585",
"identifier": "<PROJECT_ROOT>/tests/fixtures/a.js",
Expand Down Expand Up @@ -470,7 +470,7 @@ exports.c = require("./c?c=3");
{
"assets": [],
"chunks": [
"main",
"909",
],
"id": "958",
"identifier": "<PROJECT_ROOT>/tests/fixtures/a.js?a=1",
Expand Down Expand Up @@ -506,7 +506,7 @@ exports.c = require("./c?c=3");
{
"assets": [],
"chunks": [
"main",
"909",
],
"id": "432",
"identifier": "<PROJECT_ROOT>/tests/fixtures/c.js?c=3",
Expand Down Expand Up @@ -543,7 +543,7 @@ exports.c = require("./c?c=3");
{
"assets": [],
"chunks": [
"main",
"909",
],
"id": "919",
"identifier": "<PROJECT_ROOT>/tests/fixtures/abc-query.js",
Expand Down Expand Up @@ -581,7 +581,7 @@ exports.c = require("./c?c=3");
],
"assetsSize": 386,
"chunks": [
"main",
"909",
],
"name": "main",
},
Expand Down
Loading

0 comments on commit d7d87e6

Please sign in to comment.