Skip to content

Commit

Permalink
Add a warning when calling addCacheGroup() with 'vendors' or the same…
Browse files Browse the repository at this point in the history
… than in createSharedEntry()
  • Loading branch information
Lyrkan committed Mar 27, 2020
1 parent e4095b3 commit 7e32b0b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/config/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ class Validator {

_validateCacheGroupNames() {
for (const groupName of Object.keys(this.webpackConfig.cacheGroups)) {
if (['defaultVendors', 'default'].includes(groupName)) {
if (['vendors', 'defaultVendors', 'default'].includes(groupName)) {
logger.warning(`Passing "${groupName}" to addCacheGroup() is not recommended, as it will override the built-in cache group by this name.`);
}

if (groupName === this.webpackConfig.sharedCommonsEntryName) {
logger.warning('Using the same name when calling createSharedEntry() and addCacheGroup() is not recommended.');
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/config/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,22 @@ describe('The validator function', () => {
expect(logger.getMessages().warning).to.have.lengthOf(1);
expect(logger.getMessages().warning[0]).to.include('Passing "defaultVendors" to addCacheGroup() is not recommended');
});

it('warning with addCacheGroup() and a similar createSharedEntry() name', () => {
const config = createConfig();
config.outputPath = '/tmp/public/build';
config.setPublicPath('/build');
config.addEntry('main', './main');
config.createSharedEntry('foo', './foo.js');
config.addCacheGroup('foo', {
test: /[\\/]main/,
});

logger.reset();
logger.quiet();
validator(config);

expect(logger.getMessages().warning).to.have.lengthOf(1);
expect(logger.getMessages().warning[0]).to.include('Using the same name when calling createSharedEntry() and addCacheGroup() is not recommended.');
});
});

0 comments on commit 7e32b0b

Please sign in to comment.