Skip to content

Commit

Permalink
fix: prefetch flag implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed May 26, 2020
1 parent c0c7f8c commit 6f982d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
25 changes: 25 additions & 0 deletions packages/webpack-cli/__tests__/AdvancedGroup.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
7 changes: 3 additions & 4 deletions packages/webpack-cli/lib/groups/AdvancedGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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) {
Expand Down

0 comments on commit 6f982d5

Please sign in to comment.