diff --git a/packages/webpack-cli/__tests__/ZeroConfigGroup.test.js b/packages/webpack-cli/__tests__/ZeroConfigGroup.test.js index 6fd132ac3b8..22d82a397f0 100644 --- a/packages/webpack-cli/__tests__/ZeroConfigGroup.test.js +++ b/packages/webpack-cli/__tests__/ZeroConfigGroup.test.js @@ -42,4 +42,15 @@ describe('GroupHelper', function() { const result = group.run(); expect(result.options.mode).toEqual('development'); }); + + it('should handle the mode option [none]', () => { + const group = new ZeroConfigGroup([ + { + mode: 'none', + }, + ]); + + const result = group.run(); + expect(result.options.mode).toEqual('development'); + }); }); diff --git a/packages/webpack-cli/lib/groups/ZeroConfigGroup.js b/packages/webpack-cli/lib/groups/ZeroConfigGroup.js index c50acf4c74b..9333d904fee 100644 --- a/packages/webpack-cli/lib/groups/ZeroConfigGroup.js +++ b/packages/webpack-cli/lib/groups/ZeroConfigGroup.js @@ -34,6 +34,18 @@ class ZeroConfigGroup extends GroupHelper { ); return this.args.mode; } + if (isNoMode && this.args.mode) { + logger.warn( + 'You Provided both mode and no-mode arguments. You Should Provide just one. "mode" will be used.' + ) + } + if (isNoMode && (this.args.dev || this.args.prod)) { + logger.warn( + `You provided both no-mode and ${ + this.args.prod ? '--prod' : '--dev' + } arguments. You should provide just one, "${this.args.prod ? '--prod' : '--dev'}" will be used`, + ); + } if (this.args.mode) { return this.args.mode; } diff --git a/test/help/__snapshots__/help-single-arg.test.js.snap b/test/help/__snapshots__/help-single-arg.test.js.snap index 731eb62f5bf..25dab86522b 100644 --- a/test/help/__snapshots__/help-single-arg.test.js.snap +++ b/test/help/__snapshots__/help-single-arg.test.js.snap @@ -44,7 +44,8 @@ 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 string 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/no-mode/no-mode.test.js b/test/no-mode/no-mode.test.js new file mode 100644 index 00000000000..9b651684e3e --- /dev/null +++ b/test/no-mode/no-mode.test.js @@ -0,0 +1,64 @@ +'use strict'; +const { run } = require('../utils/test-utils'); +const { stat } = require('fs'); +const { resolve } = require('path'); +describe('no-mode flag', () => { + it('should load a development config when --no-mode is passed', done => { + const { stderr, stdout } = run(__dirname, ['--no-mode']); + expect(stderr).toBeFalsy(); + expect(stdout).toBeTruthy(); + stat(resolve(__dirname, './bin/main.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + done(); + }); + }); + + it('should load a development config when --no-mode and --dev are passed', done => { + const { stderr, stdout } = run(__dirname, ['--no-mode', '--dev']); + expect(stderr).toContain('"--dev" will be used'); + expect(stdout).toBeTruthy(); + + stat(resolve(__dirname, './bin/main.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + done(); + }); + }); + + it('should load a production config when --no-mode and --prod are passed', done => { + const { stderr, stdout } = run(__dirname, ['--no-mode', '--prod']); + expect(stderr).toContain('"--prod" will be used'); + expect(stdout).toBeTruthy(); + + stat(resolve(__dirname, './bin/main.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + done(); + }); + }); + + it('should load a production config when --mode=production & --no-mode are passed', done => { + const { stderr, stdout } = run(__dirname, ['--mode', 'production', '--no-mode']); + expect(stderr).toContain('"mode" will be used'); + expect(stdout).toBeTruthy(); + + stat(resolve(__dirname, './bin/main.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + done(); + }); + }); + + it('should load a development config when --mode=development and --no-mode are passed', done => { + const { stderr, stdout } = run(__dirname, ['--mode', 'development', '--no-mode']); + expect(stderr).toContain('"mode" will be used'); + expect(stdout).toBeTruthy(); + + stat(resolve(__dirname, './bin/main.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + done(); + }); + }); +}); diff --git a/test/no-mode/src/index.js b/test/no-mode/src/index.js new file mode 100644 index 00000000000..a767aed6690 --- /dev/null +++ b/test/no-mode/src/index.js @@ -0,0 +1 @@ +console.log('Test'); \ No newline at end of file