Skip to content

Commit

Permalink
fix(bugs): to void defaultEntry override config entry
Browse files Browse the repository at this point in the history
To get the correct entry, the entry should use defaultEntry, config entry, command entry in order

ISSUES CLOSED: webpack#1288
  • Loading branch information
Mistyyyy committed Mar 7, 2020
1 parent 39f5195 commit 82165df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
13 changes: 2 additions & 11 deletions packages/webpack-cli/lib/groups/BasicGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class BasicGroup extends GroupHelper {
}
return result;
}, []);
this._excuted = false;
}
resolveFlags() {
const { args } = this;
if (!args) return
const { outputOptions, options } = this.opts;
Object.keys(args).forEach(arg => {
if (this.WEBPACK_OPTION_FLAGS.includes(arg)) {
Expand All @@ -34,21 +34,12 @@ class BasicGroup extends GroupHelper {
outputOptions.devtool = args[arg];
}
if (arg === 'entry') {
// first excute, get the default entry to void defaultEntry override config entry
if (this._excuted === false) {
if (args[arg] === null)
options[arg] = this.resolveFilePath(args[arg], 'index.js');
} else if (this._excuted === true) {
options[arg] = undefined;
if (args[arg] !== null)
options[arg] = this.resolveFilePath(args[arg], 'index.js');
}
options[arg] = this.resolveFilePath(args[arg], 'index.js');
}
});
if (outputOptions['dev']) {
outputOptions['prod'] = undefined;
}
this._excuted = true;
}

run() {
Expand Down
1 change: 0 additions & 1 deletion packages/webpack-cli/lib/utils/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ module.exports = {
name: 'entry',
usage: '--entry <path to entry file> e.g. ./src/main.js',
type: String,
defaultValue: null,
defaultOption: true,
group: BASIC_GROUP,
description: 'The entry point of your application.',
Expand Down
16 changes: 16 additions & 0 deletions packages/webpack-cli/lib/webpack-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,21 @@ class WebpackCLI extends GroupHelper {
}
}

/**
* Get the defaultEntry for merge with config rightly
* @private
* @returns {void}
*/
_handleDefaultEntry() {
if (!this.basicGroup) {
const BasicGroup = require('./groups/BasicGroup');
this.basicGroup = new BasicGroup();
}
const defaultEntry = this.basicGroup.resolveFilePath(null, 'index.js');
const options = { entry: defaultEntry };
this._mergeOptionsToConfiguration(options);
}

/**
* Responsible for applying defaults, if necessary
* @private\
Expand All @@ -248,6 +263,7 @@ class WebpackCLI extends GroupHelper {
async runOptionGroups() {
await Promise.resolve()
.then(() => this._handleGroupHelper(this.zeroConfigGroup))
.then(() => this._handleDefaultEntry())
.then(() => this._handleGroupHelper(this.basicGroup))
.then(() => this._handleGroupHelper(this.configGroup))
.then(() => this._handleGroupHelper(this.outputGroup))
Expand Down

0 comments on commit 82165df

Please sign in to comment.