diff --git a/packages/webpack-cli/__tests__/AdvancedGroup.test.js b/packages/webpack-cli/__tests__/AdvancedGroup.test.js new file mode 100644 index 00000000000..ca665e71c24 --- /dev/null +++ b/packages/webpack-cli/__tests__/AdvancedGroup.test.js @@ -0,0 +1,25 @@ +const AdvancedGroup = require('../lib/groups/AdvancedGroup'); + +describe('AdvancedGroup', function () { + it('should load the HMR Plugin', () => { + const group = new AdvancedGroup([ + { + hot: true, + }, + ]); + + const result = group.run(); + expect(result.options.plugins[0].constructor.name).toEqual('HotModuleReplacementPlugin'); + }); + + it('should load the Prefetch Plugin', () => { + const group = new AdvancedGroup([ + { + prefetch: 'url', + }, + ]); + + const result = group.run(); + expect(result.options.plugins[0].constructor.name).toEqual('PrefetchPlugin'); + }); +}); diff --git a/packages/webpack-cli/lib/groups/AdvancedGroup.js b/packages/webpack-cli/lib/groups/AdvancedGroup.js index 64a5bc17800..8b46bd6f2cc 100644 --- a/packages/webpack-cli/lib/groups/AdvancedGroup.js +++ b/packages/webpack-cli/lib/groups/AdvancedGroup.js @@ -13,7 +13,7 @@ class AdvancedGroup extends GroupHelper { if (args.hot) { const { HotModuleReplacementPlugin } = require('webpack'); const hotModuleVal = new HotModuleReplacementPlugin(); - if (options && options.plugins) { + if (options.plugins) { options.plugins.unshift(hotModuleVal); } else { options.plugins = [hotModuleVal]; @@ -22,11 +22,10 @@ class AdvancedGroup extends GroupHelper { if (args.prefetch) { const { PrefetchPlugin } = require('webpack'); const prefetchVal = new PrefetchPlugin(null, args.prefetch); - if (options && options.plugins) { + if (options.plugins) { options.plugins.unshift(prefetchVal); } else { - // Currently the Plugin function is not functional -> https://github.com/webpack/webpack-cli/pull/1140#discussion_r376761359 - // options.plugins = [prefetchVal]; + options.plugins = [prefetchVal]; } } if (args.target) {