diff --git a/packages/webpack-cli/__tests__/applyCLIPlugin.test.js b/packages/webpack-cli/__tests__/applyCLIPlugin.test.js index 7c90277c5a1..7889a7af624 100644 --- a/packages/webpack-cli/__tests__/applyCLIPlugin.test.js +++ b/packages/webpack-cli/__tests__/applyCLIPlugin.test.js @@ -5,7 +5,7 @@ const applyCLIPlugin = new webpackCLI().applyCLIPlugin; describe('CLIPluginResolver', () => { it('should add CLI plugin to single compiler object', async () => { - const result = await applyCLIPlugin({ options: {} }, { hot: true, prefetch: true }); + const result = await applyCLIPlugin({ options: {}, path: new WeakMap() }, { hot: true, prefetch: true }); expect(result.options.plugins[0] instanceof CLIPlugin).toBeTruthy(); expect(result.options.plugins[0].options).toEqual({ configPath: undefined, @@ -18,7 +18,7 @@ describe('CLIPluginResolver', () => { }); it('should add CLI plugin to multi compiler object', async () => { - const result = await applyCLIPlugin({ options: [{}, {}] }, { hot: true, prefetch: true }); + const result = await applyCLIPlugin({ options: [{}, {}], path: new WeakMap() }, { hot: true, prefetch: true }); expect(result.options[0].plugins[0] instanceof CLIPlugin).toBeTruthy(); expect(result.options[1].plugins[0] instanceof CLIPlugin).toBeTruthy(); expect(result.options).toEqual([ diff --git a/packages/webpack-cli/lib/plugins/CLIPlugin.js b/packages/webpack-cli/lib/plugins/CLIPlugin.js index 350ee33e573..b6a2ead5562 100644 --- a/packages/webpack-cli/lib/plugins/CLIPlugin.js +++ b/packages/webpack-cli/lib/plugins/CLIPlugin.js @@ -41,7 +41,12 @@ class CLIPlugin { const pluginName = 'webpack-cli'; const getCompilationName = () => (compiler.name ? ` '${compiler.name}'` : ''); + const { configPath } = this.options; + compiler.hooks.run.tap(pluginName, () => { + if (configPath) { + this.logger.log(`Using config ${configPath}`); + } this.logger.log(`Compilation${getCompilationName()} starting...`); }); @@ -52,6 +57,10 @@ class CLIPlugin { this.logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.'); } + if (configPath) { + this.logger.log(`Using config ${configPath}`); + } + this.logger.log(`Compilation${getCompilationName()} starting...`); }); diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index 6e049c5b19d..4ce7ad3254f 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -1631,7 +1631,7 @@ class WebpackCLI { configOptions.plugins.unshift( new CLIPlugin({ - configPath: config.path, + configPath: config.path.get(configOptions), helpfulOutput: !cliOptions.json, hot: cliOptions.hot, progress: cliOptions.progress, diff --git a/test/build/basic/basic.test.js b/test/build/basic/basic.test.js index 01481187f45..ce3f8f7beee 100644 --- a/test/build/basic/basic.test.js +++ b/test/build/basic/basic.test.js @@ -1,5 +1,5 @@ 'use strict'; - +const { resolve } = require('path'); const { run } = require('../../utils/test-utils'); describe('bundle command', () => { @@ -140,4 +140,12 @@ describe('bundle command', () => { expect(stderr).toContain("Run 'webpack --help' to see available commands and options"); expect(stdout).toBeFalsy(); }); + + it('should log supplied config when logging level is log', () => { + const { exitCode, stderr, stdout } = run(__dirname, ['--config', './log.config.js']); + expect(exitCode).toBe(0); + const configPath = resolve(__dirname, './log.config.js'); + expect(stderr).toContain(`Using config ${configPath}`); + expect(stdout).toBeTruthy(); + }); }); diff --git a/test/build/basic/log.config.js b/test/build/basic/log.config.js new file mode 100644 index 00000000000..70619a29563 --- /dev/null +++ b/test/build/basic/log.config.js @@ -0,0 +1,6 @@ +module.exports = { + mode: 'development', + infrastructureLogging: { + level: 'log', + }, +}; diff --git a/test/serve/basic/log.config.js b/test/serve/basic/log.config.js new file mode 100644 index 00000000000..70619a29563 --- /dev/null +++ b/test/serve/basic/log.config.js @@ -0,0 +1,6 @@ +module.exports = { + mode: 'development', + infrastructureLogging: { + level: 'log', + }, +}; diff --git a/test/serve/basic/serve-basic.test.js b/test/serve/basic/serve-basic.test.js index d215cea596e..e7b0b14170e 100644 --- a/test/serve/basic/serve-basic.test.js +++ b/test/serve/basic/serve-basic.test.js @@ -329,4 +329,12 @@ describe('basic serve usage', () => { expect(stderr).toContain("Error: Unknown option '--unknown-flag'"); expect(stdout).toBeFalsy(); }); + + it('should log used supplied config with serve', async () => { + const { stderr, stdout } = await runServe(__dirname, ['--config', 'log.config.js']); + + const configPath = path.resolve(__dirname, './log.config.js'); + expect(stderr).toContain(`Using config ${configPath}`); + expect(stdout).toBeTruthy(); + }); }); diff --git a/test/watch/basic/basic.test.js b/test/watch/basic/basic.test.js index 29013daeff3..0b47cfc05eb 100644 --- a/test/watch/basic/basic.test.js +++ b/test/watch/basic/basic.test.js @@ -176,4 +176,12 @@ describe('basic', () => { expect(stderr).toContain("Run 'webpack --help' to see available commands and options"); expect(stdout).toBeFalsy(); }); + + it('should log supplied config with watch', async () => { + const { stderr, stdout } = await run(__dirname, ['watch', '--config', 'log.config.js']); + + const configPath = resolve(__dirname, './log.config.js'); + expect(stderr).toContain(`Using config ${configPath}`); + expect(stdout).toBeTruthy(); + }); }); diff --git a/test/watch/basic/log.config.js b/test/watch/basic/log.config.js new file mode 100644 index 00000000000..70619a29563 --- /dev/null +++ b/test/watch/basic/log.config.js @@ -0,0 +1,6 @@ +module.exports = { + mode: 'development', + infrastructureLogging: { + level: 'log', + }, +};