Skip to content

--config-name fails for a function returning an array of configurations #1990

@andersk

Description

@andersk

When webpack.config.js exports a function returning an array of named configurations, webpack --config-name=NAME can’t find them. It incorrectly complains [webpack-cli] Configuration with name "NAME" was not found.

$ webpack --version

webpack-cli 4.1.0

webpack 5.3.0

$ cat >src.js <<EOF
console.log("Hello, world!")
EOF

$ cat >webpack.config.js <<EOF
module.exports = () => [
  { name: "a", output: { filename: "a.js" } },
  { name: "b", output: { filename: "b.js" } },
];

$ webpack 
[webpack-cli] Compilation finished
a:
  asset a.js 29 bytes [compared for emit] [minimized] (name: main)
  ./src.js 29 bytes [built] [code generated]
  a (webpack 5.3.0) compiled successfully in 147 ms

b:
  asset b.js 29 bytes [emitted] [minimized] (name: main)
  ./src.js 29 bytes [built] [code generated]
  b (webpack 5.3.0) compiled successfully in 139 ms

$ webpack --config-name=a
[webpack-cli] Configuration with name "a" was not found.

It works for a function returning a single configuration:

$ cat >webpack.config.js <<EOF
module.exports = () => ({ name: "a", output: { filename: "a.js" } });
EOF

$ webpack --config-name=a
[webpack-cli] Compilation finished
asset a.js 29 bytes [compared for emit] [minimized] (name: main)
./src.js 29 bytes [built] [code generated]
a (webpack 5.3.0) compiled successfully in 157 ms

or for an array that’s not wrapped in a function:

$ cat >webpack.config.js <<EOF
module.exports = [
  { name: "a", output: { filename: "a.js" } },
  { name: "b", output: { filename: "b.js" } },
];
EOF

$ webpack --config-name=a
[webpack-cli] Compilation finished
asset a.js 29 bytes [compared for emit] [minimized] (name: main)
./src.js 29 bytes [built] [code generated]
a (webpack 5.3.0) compiled successfully in 142 ms

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions