Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cli): better group handling (#1204)
* chore: refactored how configuration is created * chore(cli): refactor how the CLI handles configuration and cli arguments * chore(cli): added devltool inside the zero configs * fix: update lib/groups/StatsGroup.js Co-Authored-By: Rishabh Chawla <rishabh31121999@gmail.com> * fix: update lib/groups/ZeroConfigGroup.js Co-Authored-By: Rishabh Chawla <rishabh31121999@gmail.com> * fix: update lib/groups/ZeroConfigGroup.js Co-Authored-By: Rishabh Chawla <rishabh31121999@gmail.com> * chore(cli): applied suggestions Co-Authored-By: Rishabh Chawla <rishabh31121999@gmail.com> * chore(cli): post code review * chore(cli): grammar and code styling Co-authored-by: Rishabh Chawla <rishabh31121999@gmail.com>
- Loading branch information
1 parent
861e9f8
commit 5e9639f
Showing
26 changed files
with
391 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"printWidth": 140 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const GroupHelper = require('../utils/GroupHelper'); | ||
|
||
/** | ||
* ZeroConfigGroup creates a zero configuration based on the environment | ||
*/ | ||
class ZeroConfigGroup extends GroupHelper { | ||
constructor(options) { | ||
super(options); | ||
} | ||
|
||
/** | ||
* It determines the mode to pass to webpack compiler | ||
* @returns {string} The mode | ||
*/ | ||
getEnvFromOptionsAndMode() { | ||
if (process.env.NODE_ENV && (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'development')) { | ||
return process.env.NODE_ENV; | ||
} else if (this.args.prod) { | ||
return 'production'; | ||
} else if (this.args.dev) { | ||
return 'development'; | ||
} | ||
return 'production'; | ||
} | ||
|
||
resolveZeroConfig() { | ||
const defaultConfigType = this.getEnvFromOptionsAndMode(); | ||
const defaultConfig = require(`./${defaultConfigType}-config`)(); | ||
|
||
const isEntryObject = defaultConfig.entry && defaultConfig.entry instanceof Object; | ||
const isOutputDefined = defaultConfig.output && defaultConfig.output.filename; | ||
const isConflictingOutput = isEntryObject && isOutputDefined && defaultConfig.output.filename === 'bundle.js'; | ||
if (isConflictingOutput) { | ||
defaultConfig.output.filename = '[name].bundle.js'; | ||
} | ||
this.opts.options = defaultConfig; | ||
} | ||
|
||
run() { | ||
this.resolveZeroConfig(); | ||
return this.opts; | ||
} | ||
} | ||
|
||
module.exports = ZeroConfigGroup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,13 @@ | ||
const { join, resolve } = require('path'); | ||
const TerserPlugin = require('terser-webpack-plugin'); | ||
|
||
const defaultOutputPath = resolve(join(process.cwd(), 'dist')); | ||
|
||
module.exports = () => ({ | ||
mode: 'development', | ||
entry: './index.js', | ||
devtool: 'eval', | ||
output: { | ||
path: defaultOutputPath, | ||
filename: 'bundle.js', | ||
}, | ||
|
||
optimization: { | ||
minimizer: [ | ||
new TerserPlugin({ | ||
sourceMap: true, | ||
}), | ||
], | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.