diff --git a/packages/webpack-cli/lib/utils/cli-flags.js b/packages/webpack-cli/lib/utils/cli-flags.js index 5264a2146e5..9be53efe147 100644 --- a/packages/webpack-cli/lib/utils/cli-flags.js +++ b/packages/webpack-cli/lib/utils/cli-flags.js @@ -1,3 +1,4 @@ +const { logger } = require('@webpack-cli/logger'); const HELP_GROUP = 'help'; const CONFIG_GROUP = 'config'; const BASIC_GROUP = 'basic'; @@ -286,11 +287,17 @@ module.exports = { { name: 'mode', usage: '--mode ', - type: String, + type: (value) => { + if (value === 'development' || value === 'production' || value === 'none') { + return value + } else { + logger.warn('You provided invalid value for "mode" option, webpack will fallback to "production" for this value.') + } + }, group: ZERO_CONFIG_GROUP, description: 'Defines the mode to pass to webpack', link: 'https://webpack.js.org/concepts/#mode', - acceptedValues: ["development", "production"] + acceptedValues: ["development", "production", "none"] }, { name: 'no-mode', diff --git a/test/help/__snapshots__/help-single-arg.test.js.snap b/test/help/__snapshots__/help-single-arg.test.js.snap index 3ef3bcec597..079bf435b25 100644 --- a/test/help/__snapshots__/help-single-arg.test.js.snap +++ b/test/help/__snapshots__/help-single-arg.test.js.snap @@ -44,7 +44,7 @@ Options --standard Prints standard output -d, --dev Run development build -p, --prod Run production build - --mode string Defines the mode to pass to webpack + --mode type Defines the mode to pass to webpack --no-mode Sets mode="none" which disables any default behavior --version Get current version --node-args string[] NodeJS flags diff --git a/test/mode/prod/prod.test.js b/test/mode/prod/prod.test.js index 6d6482c2037..4d30df974d7 100644 --- a/test/mode/prod/prod.test.js +++ b/test/mode/prod/prod.test.js @@ -60,4 +60,16 @@ describe('mode flags', () => { done(); }); }); + + it('should load a production config when --mode=abcd is passed', done => { + const { stderr, stdout } = run(__dirname, ['--mode', 'abcd']); + expect(stderr).toContain('"production" for this value'); + expect(stdout).toBeTruthy(); + + stat(resolve(__dirname, './bin/main.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + done(); + }); + }); });