-
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.
- Loading branch information
Showing
3 changed files
with
49 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
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,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 TraverseChunkGraphPlugin = require("${path.join(__dirname, 'plugin.cjs')}"); | ||
module.exports.plugins.push(new TraverseChunkGraphPlugin()); | ||
`; | ||
} | ||
} |
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 PLUGIN_NAME = "TraverseChunkModulesPlugin"; | ||
|
||
class TraverseChunkModulesPlugin { | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.processAssets.tap(PLUGIN_NAME, () => { | ||
const visitedModules = new Set(); | ||
|
||
for (const chunk of compilation.chunks.values()) { | ||
const modules = compilation.chunkGraph.getChunkModulesIterable(chunk); | ||
for (const module of modules) { | ||
if (modules in module) { | ||
for (const subModule of module.modules) { | ||
visitedModules.add(subModule); | ||
} | ||
} else { | ||
visitedModules.add(module); | ||
} | ||
} | ||
} | ||
|
||
console.log('visited modules number', visitedModules.size); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = TraverseChunkModulesPlugin; |