From 0d002b1e5d2cc4dabbe72c453a8ae4c77787e7d2 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Tue, 28 Jan 2020 13:13:22 -0700 Subject: [PATCH 1/2] Adding config.set('singleEntry'). Resolves #230. --- README.md | 3 +++ src/Config.js | 16 +++++++++++----- test/Config.js | 10 ++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1332bd9..71081f9 100644 --- a/README.md +++ b/README.md @@ -408,6 +408,9 @@ config.entryPoints config.entryPoints .get(name) .clear() + +// Set entry to be a single value instead of a ChainedMap +config.set('singleEntry', 'src/index.js') ``` #### Config output: shorthand methods diff --git a/src/Config.js b/src/Config.js index 4452e04..0d7fa77 100644 --- a/src/Config.js +++ b/src/Config.js @@ -37,6 +37,7 @@ module.exports = class extends ChainedMap { 'recordsInputPath', 'recordsPath', 'recordsOutputPath', + 'singleEntry', 'stats', 'target', 'watch', @@ -117,6 +118,14 @@ module.exports = class extends ChainedMap { toConfig() { const entryPoints = this.entryPoints.entries() || {}; + const entry = this.has('singleEntry') + ? this.get('singleEntry') + : Object.keys(entryPoints).reduce( + (acc, key) => + Object.assign(acc, { [key]: entryPoints[key].values() }), + {}, + ); + return this.clean( Object.assign(this.entries() || {}, { node: this.node.entries(), @@ -128,11 +137,8 @@ module.exports = class extends ChainedMap { optimization: this.optimization.toConfig(), plugins: this.plugins.values().map(plugin => plugin.toConfig()), performance: this.performance.entries(), - entry: Object.keys(entryPoints).reduce( - (acc, key) => - Object.assign(acc, { [key]: entryPoints[key].values() }), - {}, - ), + entry, + singleEntry: undefined, }), ); } diff --git a/test/Config.js b/test/Config.js index 1b9be06..d3e7c2e 100644 --- a/test/Config.js +++ b/test/Config.js @@ -61,6 +61,16 @@ test('entry', t => { ]); }); +test('single string entry', t => { + const config = new Config(); + + config.set('singleEntry', 'src/index.js'); + + t.deepEqual(config.toConfig(), { + entry: 'src/index.js', + }); +}); + test('plugin empty', t => { const config = new Config(); const instance = config From 6c46b1679ae22b8f00aae6db059b36b1e1fccc55 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Tue, 28 Jan 2020 13:15:04 -0700 Subject: [PATCH 2/2] Self review --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 71081f9..234a0e0 100644 --- a/README.md +++ b/README.md @@ -410,7 +410,7 @@ config.entryPoints .clear() // Set entry to be a single value instead of a ChainedMap -config.set('singleEntry', 'src/index.js') +config.set('singleEntry', entryPath) ``` #### Config output: shorthand methods