Skip to content

Commit

Permalink
fix: defer setting default mode to core
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed Nov 10, 2020
1 parent 8651f49 commit 19a4c8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 8 additions & 4 deletions packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -96,8 +96,6 @@ class WebpackCLI {
finalMode = configMode;
} else if (NODE_ENV && (NODE_ENV === PRODUCTION || NODE_ENV === DEVELOPMENT)) {
finalMode = NODE_ENV;
} else {
finalMode = PRODUCTION;
}
return finalMode;
};
Expand Down Expand Up @@ -177,10 +175,16 @@ class WebpackCLI {
// Todo - handle multi config for all flags
finalOptions.options = configOptions.map(() => ({ ...finalOptions.options }));
configOptions.forEach((configObject, index) => {
finalOptions.options[index].mode = assignMode(mode, configObject);
const resolvedMode = assignMode(mode, configObject);
if (resolvedMode) {
finalOptions.options[index].mode = resolvedMode;
}
});
} else {
finalOptions.options.mode = assignMode(mode, configOptions);
const resolvedMode = assignMode(mode, configOptions);
if (resolvedMode) {
finalOptions.options.mode = resolvedMode;
}
}
return finalOptions;
}
Expand Down
5 changes: 3 additions & 2 deletions test/mode/mode-single-arg/mode-single-arg.test.js
Expand Up @@ -2,12 +2,13 @@
const { run } = require('../../utils/test-utils');

describe('mode flags', () => {
it('should set mode=production by default', () => {
it('should not set mode=production by default', () => {
const { stderr, stdout, exitCode } = run(__dirname);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`mode: 'production'`);
expect(stdout).not.toContain(`mode: 'production'`);
expect(stdout).toContain(`The 'mode' option has not been set, webpack will fallback to 'production' for this value.`);
});

it('should load a development config when --mode=development is passed', () => {
Expand Down

0 comments on commit 19a4c8f

Please sign in to comment.