Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Removing empty entities from cluttering configuration object
Browse files Browse the repository at this point in the history
  • Loading branch information
eliperelman committed Mar 4, 2017
1 parent 2468eaa commit b428e55
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpack-chain",
"version": "1.4.2",
"version": "1.4.3",
"main": "src/Config.js",
"repository": "mozilla-rpweb/webpack-chain",
"keywords": [
Expand Down
8 changes: 7 additions & 1 deletion src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ class Config {

toConfig() {
const entries = this.entries.entries();
const plugins = this.plugins.values()
.map(value => value.init(value.plugin, value.args));

const config = Object.assign({}, this.options.entries(), {
node: this.node.entries(),
output: this.output.entries(),
resolve: this.resolve.toConfig(),
resolveLoader: this.resolveLoader.toConfig(),
devServer: this.devServer.entries(),
plugins: this.plugins.values().map(value => value.init(value.plugin, value.args)),
module: this.module.toConfig(),
entry: entries && Object
.keys(entries)
Expand All @@ -74,6 +76,10 @@ class Config {
}, {})
});

if (plugins.length) {
config.plugins = plugins;
}

return Object
.keys(config)
.reduce((acc, key) => {
Expand Down
13 changes: 9 additions & 4 deletions src/Resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ module.exports = class extends ChainedMap {
}

toConfig() {
return Object.assign({
modules: this.modules.values(),
extensions: this.extensions.values()
}, this.entries());
const modules = this.modules.values();
const extensions = this.extensions.values();
const entries = this.entries() || {};

if (!modules.length && !extensions.length && !Object.keys(entries).length) {
return;
}

return Object.assign({ modules, extensions }, entries);
}

merge(obj) {
Expand Down
11 changes: 8 additions & 3 deletions src/ResolveLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ module.exports = class extends ChainedMap {
}

toConfig() {
return Object.assign({
modules: this.modules.values()
}, this.entries());
const modules = this.modules.values();
const entries = this.entries() || {};

if (!modules.length && !Object.keys(entries).length) {
return;
}

return Object.assign({ modules }, entries);
}

merge(obj) {
Expand Down

0 comments on commit b428e55

Please sign in to comment.