Skip to content

Commit

Permalink
feat: add --config-name flag
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Aug 18, 2020
1 parent d3e2936 commit 3845ef1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/webpack-cli/lib/groups/ConfigGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { extensions, jsVariants } = require('interpret');
const GroupHelper = require('../utils/GroupHelper');
const rechoir = require('rechoir');
const MergeError = require('../utils/errors/MergeError');
const logger = require('../utils/logger');

// Order defines the priority, in increasing order
// example - config file lookup will be in order of .webpack/webpack.config.development.js -> webpack.config.development.js -> webpack.config.js
Expand Down Expand Up @@ -117,6 +118,14 @@ class ConfigGroup extends GroupHelper {
const newOptions = configOptions(formattedEnv, argv);
// When config function returns a promise, resolve it, if not it's resolved by default
newOptionsObject['options'] = await Promise.resolve(newOptions);
} else if (Array.isArray(configOptions) && this.args.configName) {
const namedOption = configOptions.filter((opt) => this.args.configName.includes(opt.name));
if (namedOption.length === 0) {
logger.error(`Configuration with name ${this.args.configName} was not found.`);
process.exit(1);
} else {
newOptionsObject['options'] = namedOption;
}
} else {
if (Array.isArray(configOptions) && !configOptions.length) {
newOptionsObject['options'] = {};
Expand Down
8 changes: 8 additions & 0 deletions packages/webpack-cli/lib/utils/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ module.exports = {
description: 'Provide path to a webpack configuration file e.g. ./webpack.config.js',
link: 'https://webpack.js.org/configuration/',
},
{
name: 'config-name',
usage: '--config-name <name of config>',
type: String,
multiple: true,
group: CONFIG_GROUP,
description: 'Name of the configuration file',
},
{
name: 'color',
usage: '--color',
Expand Down

0 comments on commit 3845ef1

Please sign in to comment.