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

Adding config.set('singleEntry'). Resolves #230. #239

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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', entryPath)
```

#### Config output: shorthand methods
Expand Down
16 changes: 11 additions & 5 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = class extends ChainedMap {
'recordsInputPath',
'recordsPath',
'recordsOutputPath',
'singleEntry',
'stats',
'target',
'watch',
Expand Down Expand Up @@ -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(),
Expand All @@ -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,
}),
);
}
Expand Down
10 changes: 10 additions & 0 deletions test/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down