2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.CLIPlugin = void 0;
6 this.options = options;
8 setupHotPlugin(compiler) {
9 const { HotModuleReplacementPlugin } = compiler.webpack || require("webpack");
10 const hotModuleReplacementPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof HotModuleReplacementPlugin));
11 if (!hotModuleReplacementPlugin) {
12 new HotModuleReplacementPlugin().apply(compiler);
15 setupPrefetchPlugin(compiler) {
16 const { PrefetchPlugin } = compiler.webpack || require("webpack");
17 new PrefetchPlugin(null, this.options.prefetch).apply(compiler);
19 async setupBundleAnalyzerPlugin(compiler) {
20 // eslint-disable-next-line node/no-extraneous-require,@typescript-eslint/no-var-requires
21 const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
22 const bundleAnalyzerPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof BundleAnalyzerPlugin));
23 if (!bundleAnalyzerPlugin) {
24 new BundleAnalyzerPlugin().apply(compiler);
27 setupProgressPlugin(compiler) {
28 const { ProgressPlugin } = compiler.webpack || require("webpack");
29 const progressPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof ProgressPlugin));
30 if (!progressPlugin) {
32 profile: this.options.progress === "profile",
36 setupHelpfulOutput(compiler) {
37 const pluginName = "webpack-cli";
38 const getCompilationName = () => (compiler.name ? `'${compiler.name}'` : "");
39 const logCompilation = (message) => {
40 if (process.env.WEBPACK_CLI_START_FINISH_FORCE_LOG) {
41 process.stderr.write(message);
44 this.logger.log(message);
47 const { configPath } = this.options;
48 compiler.hooks.run.tap(pluginName, () => {
49 const name = getCompilationName();
50 logCompilation(`Compiler${name ? ` ${name}` : ""} starting... `);
52 this.logger.log(`Compiler${name ? ` ${name}` : ""} is using config: '${configPath}'`);
55 compiler.hooks.watchRun.tap(pluginName, (compiler) => {
56 const { bail, watch } = compiler.options;
58 this.logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.');
60 const name = getCompilationName();
61 logCompilation(`Compiler${name ? ` ${name}` : ""} starting... `);
63 this.logger.log(`Compiler${name ? ` ${name}` : ""} is using config: '${configPath}'`);
66 compiler.hooks.invalid.tap(pluginName, (filename, changeTime) => {
67 const date = new Date(changeTime);
68 this.logger.log(`File '${filename}' was modified`);
69 this.logger.log(`Changed time is ${date} (timestamp is ${changeTime})`);
71 (compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap(pluginName, () => {
72 const name = getCompilationName();
73 logCompilation(`Compiler${name ? ` ${name}` : ""} finished`);
74 process.nextTick(() => {
75 if (compiler.watchMode) {
76 this.logger.log(`Compiler${name ? `${name}` : ""} is watching files for updates...`);
82 this.logger = compiler.getInfrastructureLogger("webpack-cli");
83 if (this.options.progress) {
84 this.setupProgressPlugin(compiler);
86 if (this.options.hot) {
87 this.setupHotPlugin(compiler);
89 if (this.options.prefetch) {
90 this.setupPrefetchPlugin(compiler);
92 if (this.options.analyze) {
93 this.setupBundleAnalyzerPlugin(compiler);
95 this.setupHelpfulOutput(compiler);
98 exports.CLIPlugin = CLIPlugin;
99 module.exports = CLIPlugin;