-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add large code splitting tests
- Loading branch information
Showing
11 changed files
with
10,231 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ output | |
*.cpuprofile | ||
*.heapprofile | ||
.DS_Store | ||
cases/large-dyn-imports/src/**/ |
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
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
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,11 @@ | ||
module.exports = [ | ||
{ | ||
rebuildChangeFile: "./src/index.js", | ||
generateContent: function (originalContent, runTimes) { | ||
return ( | ||
`import "data:text/javascript,export default ${runTimes}"; | ||
` + originalContent | ||
); | ||
} | ||
} | ||
]; |
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,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>large dyn imports</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
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,3 @@ | ||
{ | ||
"name": "large-dyn-imports" | ||
} |
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,71 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const rspack = require("@rspack/core"); | ||
const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); | ||
|
||
const prod = process.env.NODE_ENV === "production"; | ||
/** @type {import("@rspack/cli").Configuration} */ | ||
|
||
module.exports = { | ||
resolve: { | ||
extensions: [".js", ".jsx"] | ||
}, | ||
entry: { main: "./src/index.js" }, | ||
plugins: [ | ||
new rspack.HtmlRspackPlugin({ | ||
template: path.resolve(__dirname, "./index.html") | ||
}), | ||
!prod && new ReactRefreshPlugin() | ||
].filter(Boolean), | ||
optimization: { | ||
splitChunks: { | ||
chunks: "all", | ||
} | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(j|t)s$/, | ||
exclude: [/[\\/]node_modules[\\/]/], | ||
loader: "builtin:swc-loader", | ||
options: { | ||
sourceMap: true, | ||
jsc: { | ||
parser: { | ||
syntax: "typescript" | ||
}, | ||
externalHelpers: true | ||
}, | ||
env: { | ||
targets: "Chrome >= 48" | ||
} | ||
} | ||
}, | ||
{ | ||
test: /\.(j|t)sx$/, | ||
loader: "builtin:swc-loader", | ||
exclude: [/[\\/]node_modules[\\/]/], | ||
options: { | ||
sourceMap: true, | ||
jsc: { | ||
parser: { | ||
syntax: "typescript", | ||
tsx: true | ||
}, | ||
transform: { | ||
react: { | ||
runtime: "automatic", | ||
development: !prod, | ||
refresh: !prod | ||
} | ||
}, | ||
externalHelpers: true | ||
}, | ||
env: { | ||
targets: "Chrome >= 48" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
}; |
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 @@ | ||
import './dynamic/dynamic-0.jsx' |
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,29 @@ | ||
import fs from "fs/promises"; | ||
import path from "path"; | ||
import { fileURLToPath } from "node:url"; | ||
import { NUM_STATIC_MODULES, NUM_REUSE_IMPORTS_PER_MODULE, NUM_STATIC_IMPORTS_PER_MODULE } from "./gen-code-splitting-case.js"; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
async function main() { | ||
const map = [] | ||
for (let i = 0; i < NUM_STATIC_MODULES; i += NUM_STATIC_IMPORTS_PER_MODULE) { | ||
// imports from i to i + NUM_STATIC_IMPORTS_PER_MODULE | ||
const depth = i / NUM_STATIC_IMPORTS_PER_MODULE | ||
map[depth] = [] | ||
|
||
// reuse imports | ||
for (let j = 0; j < NUM_REUSE_IMPORTS_PER_MODULE; j++) { | ||
let random = Math.round(Math.random() * i); | ||
if (random < i) { | ||
if (!map[depth].includes(random)) { | ||
map[depth].push(random) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fs.writeFile(path.join(__dirname, `./code-splitting-case-random-table.json`), JSON.stringify(map)) | ||
} | ||
|
||
main(); |
Oops, something went wrong.