Skip to content

Commit 7e32b0b

Browse files
committed
Add a warning when calling addCacheGroup() with 'vendors' or the same than in createSharedEntry()
1 parent e4095b3 commit 7e32b0b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/config/validator.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,13 @@ class Validator {
8080

8181
_validateCacheGroupNames() {
8282
for (const groupName of Object.keys(this.webpackConfig.cacheGroups)) {
83-
if (['defaultVendors', 'default'].includes(groupName)) {
83+
if (['vendors', 'defaultVendors', 'default'].includes(groupName)) {
8484
logger.warning(`Passing "${groupName}" to addCacheGroup() is not recommended, as it will override the built-in cache group by this name.`);
8585
}
86+
87+
if (groupName === this.webpackConfig.sharedCommonsEntryName) {
88+
logger.warning('Using the same name when calling createSharedEntry() and addCacheGroup() is not recommended.');
89+
}
8690
}
8791
}
8892
}

test/config/validator.js

+18
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,22 @@ describe('The validator function', () => {
113113
expect(logger.getMessages().warning).to.have.lengthOf(1);
114114
expect(logger.getMessages().warning[0]).to.include('Passing "defaultVendors" to addCacheGroup() is not recommended');
115115
});
116+
117+
it('warning with addCacheGroup() and a similar createSharedEntry() name', () => {
118+
const config = createConfig();
119+
config.outputPath = '/tmp/public/build';
120+
config.setPublicPath('/build');
121+
config.addEntry('main', './main');
122+
config.createSharedEntry('foo', './foo.js');
123+
config.addCacheGroup('foo', {
124+
test: /[\\/]main/,
125+
});
126+
127+
logger.reset();
128+
logger.quiet();
129+
validator(config);
130+
131+
expect(logger.getMessages().warning).to.have.lengthOf(1);
132+
expect(logger.getMessages().warning[0]).to.include('Using the same name when calling createSharedEntry() and addCacheGroup() is not recommended.');
133+
});
116134
});

0 commit comments

Comments
 (0)