Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bench.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ export default {
"10000_development-mode",
"10000_development-mode_hmr",
"10000_production-mode",
"10000_big_production-mode_disable-minimize",
"10000_production-mode_traverse-module-graph",
"arco-pro_development-mode",
"arco-pro_development-mode_hmr",
"arco-pro_production-mode",
"arco-pro_production-mode_generate-package-json-webpack-plugin",
"threejs_development-mode_10x",
"threejs_development-mode_10x_hmr",
"threejs_production-mode_10x"
"threejs_production-mode_10x",
"10000_big_production-mode",
],
rspackDirectory: process.env.RSPACK_DIR
};
20 changes: 20 additions & 0 deletions lib/addons/traverse-module-graph/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import path from "path";
import url from "url";
import { Addon } from "../common.js";

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

export default class extends Addon {
options = {
times: 10
};
async afterSetup(ctx) {
ctx.config =
ctx.config +
`
module.exports.plugins = module.exports.plugins || [];
const TraverseModuleGraphPlugin = require("${path.join(__dirname, 'plugin.cjs')}");
module.exports.plugins.push(new TraverseModuleGraphPlugin());
`;
}
}
34 changes: 34 additions & 0 deletions lib/addons/traverse-module-graph/plugin.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const PLUGIN_NAME = "TraverseModuleGraphPlugin";

class TraverseModuleGraphPlugin {
apply(compiler) {
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
compilation.hooks.finishModules.tap(PLUGIN_NAME, () => {
const entries = compilation.entries.values();

const visitedModules = new Set();

function traverse(dependency) {
const module = compilation.moduleGraph.getModule(dependency);
if (module) {
if (visitedModules.has(module)) {
return;
}
visitedModules.add(module);
for (const dep of module.dependencies) {
traverse(dep)
}
}
}

for (const entry of entries) {
for (const dependency of entry.dependencies) {
traverse(dependency)
}
}
});
});
}
}

module.exports = TraverseModuleGraphPlugin;