Description
Feature request
I propose to add a new command to Webpack CLI that outputs a project's current configuration in full detail – including default values.
The output should be a full-fledged JS file, with actual values used for each single configuration property. If no configuration value is provided, the actual and the computed default value should be added in a comment next to the value (which usually is undefined
, as it is undefined).
For example, given a configuration like this:
module.exports =
{
mode: "development",
};
… the proposed Webpack CLI config
command:
npx webpack config [config-path [config-name]]
… should output the following to stdout
:
Excerpt only:
const path = require('path');
module.exports = {
target: undefined /* "web" */,
mode: "development",
entry: undefined /* "./src" */,
output: {
path: undefined /* path.resolve(__dirname, "dist") */ /* "C:\repos\myproject\dist" */,
filename: undefined /* "[name].js" */,
publicPath: undefined /* "/assets/" */,
// ...
// ...
// ...
optimization: {
chunkIds: undefined /* "size" */,
moduleIds: undefined /* "size" */,
mangleExports: undefined /* "size" */,
minimize: undefined /* true */,
minimizer: undefined /* null */
)
}
Please note the following in the above excerpt:
mode
is the only property not being output asundefined
, because it's being defined in the configuration file.mode
is the only property without a default value comment, because no default is applied to it.- Suppose, no
browserlist
file exists in this example. Then the actual default value for thetarget
property is"web"
, as is depicted in the excerpt above. - The actual default value for the
output.path
property is a computation (path.resolve(__dirname, "dist")
). This will result in a second comment being added to the property, containing the computed default value, which is"C:\repos\myproject\dist"
.
What is motivation or use case for adding/changing the behavior?
Although there are many useful default values being applied to Webpack when a small configuration in a Webpack configuration file is used, it's still obscure which actual values are being used for all untouched Webpack configuration properties. So, it's hard to figure out unwanted or less than perfect build behaviour.
Moreover, with the proposed output, GUI tools can be written to provide form based helpers or linters for editing/optimizing webpack configurations.
What is the expected behavior?
A new Webpack CLI command, config
, should output a configuration's actual and default values. Values not defined in the config file should output undefined
as the property value plus an additional comment added, showing their actual default value. If that actual default value is a computation, a second comment should be added to the output, showing the computed value.
NB: Redirection of the output to a file should be possible.
How should this be implemented in your opinion?
An additional CLI command should be written, resulting in a syntax like the following:
npx webpack config [config-path [config-name]]
Are you willing to work on this yourself?
no