MCPcopy Create free account
hub / github.com/webpack/webpack-cli / CLIPlugin

Class CLIPlugin

packages/webpack-cli/src/plugins/cli-plugin.ts:13–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11}
12
13export default class CLIPlugin {
14 logger!: ReturnType<Compiler["getInfrastructureLogger"]>;
15
16 options: CLIPluginOptions;
17
18 constructor(options: CLIPluginOptions) {
19 this.options = options;
20 }
21
22 async setupBundleAnalyzerPlugin(compiler: Compiler) {
23 // @ts-expect-error No types right now
24 const { BundleAnalyzerPlugin } = (await import("webpack-bundle-analyzer")).default;
25
26 const bundleAnalyzerPlugin = compiler.options.plugins.some(
27 (plugin) => plugin instanceof BundleAnalyzerPlugin,
28 );
29
30 if (!bundleAnalyzerPlugin) {
31 new BundleAnalyzerPlugin().apply(compiler);
32 }
33 }
34
35 static #progressStates: [number, ...string[]][] = [];
36
37 setupProgressPlugin(compiler: Compiler) {
38 const { ProgressPlugin } = compiler.webpack;
39 const progressPlugin = compiler.options.plugins.some(
40 (plugin) => plugin instanceof ProgressPlugin,
41 );
42
43 if (progressPlugin) {
44 return;
45 }
46
47 const isProfile = this.options.progress === "profile";
48
49 const options: ConstructorParameters<typeof ProgressPlugin>[0] = {
50 profile: isProfile,
51 };
52
53 if (this.options.isMultiCompiler && ProgressPlugin.createDefaultHandler) {
54 const handler = ProgressPlugin.createDefaultHandler(
55 isProfile,
56 compiler.getInfrastructureLogger("webpack.Progress"),
57 );
58 const idx = CLIPlugin.#progressStates.length;
59
60 CLIPlugin.#progressStates[idx] = [0];
61
62 options.handler = (progress: number, msg: string, ...args: string[]) => {
63 CLIPlugin.#progressStates[idx] = [progress, msg, ...args];
64
65 let sum = 0;
66
67 for (const [progress] of CLIPlugin.#progressStates) {
68 sum += progress;
69 }
70

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected