Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16933 from scameron/deterministic-moduleids
Fix non-deterministic moduleId assignment
- Loading branch information
Showing
10 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default function test() { | ||
const a = 1; | ||
const b = 2; | ||
const c = 3; | ||
const d = 4; | ||
const f = 5; | ||
const e = 6; | ||
|
||
return a + b + c + d + f + e; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
async function test() { | ||
const a = 1; | ||
const b = 2; | ||
const c = 3; | ||
const d = 4; | ||
const f = 5; | ||
const e = 6; | ||
|
||
await import("./async.js"); | ||
|
||
return a + b + c + d + f + e; | ||
} | ||
|
||
test(); | ||
|
||
export { test } | ||
export default test; | ||
|
||
test(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { test } from "./file-1.js"; | ||
|
||
export default function foobar() { | ||
return "test" + test(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function test() { | ||
return "test"; | ||
} | ||
|
||
test(); | ||
|
||
module.exports = "test"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import file from "./file-1.js"; | ||
import file2 from "./file-2.js"; | ||
|
||
async function test() { | ||
const a = 1; | ||
const b = 2; | ||
const c = 3; | ||
const d = 4; | ||
const f = 5; | ||
const e = 6; | ||
|
||
await import(/* webpackMode: "eager" */"./async.js"); | ||
await import(/* webpackMode: "eager" */"./file-3.js"); | ||
|
||
return a + b + c + d + f + e; | ||
} | ||
|
||
test(); | ||
|
||
export { test, file, file2 } | ||
export default function foo() { | ||
return "test"; | ||
} | ||
|
||
test(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import img from "./1.jpg"; | ||
import file from "./file.js"; | ||
|
||
it("should compile", () => { | ||
expect(typeof img).toBe("string"); | ||
expect(typeof file).toBe("function"); | ||
}); |
28 changes: 28 additions & 0 deletions
28
test/configCases/contenthash/module-ids-size/test.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const findOutputFiles = require("../../../helpers/findOutputFiles"); | ||
|
||
const allAssets = new Set(); | ||
const allBundles = new Set(); | ||
|
||
module.exports = { | ||
findBundle: function (i, options) { | ||
const bundle = findOutputFiles(options, new RegExp(`^bundle${i}`))[0]; | ||
|
||
allBundles.add(/\.([^.]+)\./.exec(bundle)[1]); | ||
|
||
let asset; | ||
|
||
switch (i) { | ||
case 0: | ||
asset = findOutputFiles(options, /^1\.[^.]*\.jpg$/, "img")[0]; | ||
break; | ||
} | ||
|
||
if (asset) allAssets.add(asset); | ||
|
||
return `./${bundle}`; | ||
}, | ||
afterExecute: () => { | ||
// Bundles have the same contenthash | ||
expect(allBundles.size).toBe(1); | ||
} | ||
}; |
37 changes: 37 additions & 0 deletions
37
test/configCases/contenthash/module-ids-size/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** @type {import("../../../../").Configuration} */ | ||
module.exports = [ | ||
{ | ||
output: { | ||
filename: "bundle0.[contenthash].a.js", | ||
assetModuleFilename: "img/[name].a.[contenthash][ext]" | ||
}, | ||
optimization: { | ||
moduleIds: "size" | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jpg$/, | ||
type: "asset/resource" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
output: { | ||
filename: "bundle1.[contenthash].b.js", | ||
assetModuleFilename: "img/[name].a.[contenthash][ext]" | ||
}, | ||
optimization: { | ||
moduleIds: "size" | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jpg$/, | ||
type: "asset/resource" | ||
} | ||
] | ||
} | ||
} | ||
]; |