Skip to content

Commit 68d94b2

Browse files
committed
feat: remove special handling of cache configuration
In webpack verion 4 special code was necessary to make the cache work with grunts multi-target system. The cache plugin in version 4 was storing one global cache for all compilers it was attached to. In webpack 5 this is not neccessary anymore as the cache now creates a new storage for each compiler.
1 parent 21d90dc commit 68d94b2

File tree

5 files changed

+1
-82
lines changed

5 files changed

+1
-82
lines changed

src/options/WebpackOptionHelper.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,7 @@ class WebpackOptionHelper extends OptionHelper {
1212
const options = this.getOptions();
1313

1414
if (Array.isArray(options)) {
15-
return options.map((opt) => this.filterOptions(opt));
16-
}
17-
18-
return this.filterOptions(options);
19-
}
20-
21-
filterOptions(options) {
22-
if (!options.watch) {
23-
// ensure cache is disabled in non watch mode, as we add our own CachePlugin to support
24-
// multiple targets in one run with different caches
25-
options.cache = false;
26-
}
27-
28-
// ensure that when we send the cache option to webpack in watch mode it is not the function
29-
// TODO: this is workaround and should be handled in a more generic way
30-
if (typeof options.cache === "function") {
31-
options.cache = options.cache(options);
15+
return options.map((opt) => this.filterGruntOptions(opt));
3216
}
3317

3418
return this.filterGruntOptions(options);

src/options/__tests__/WebpackOptionHelper.test.js

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,6 @@
11
import WebpackOptionHelper from "../WebpackOptionHelper";
22

33
describe("WebpackOptionHelper", () => {
4-
test("cache stays enabled in watch mode", () => {
5-
const options = { watch: true, cache: true };
6-
const helper = new WebpackOptionHelper();
7-
8-
const result = helper.filterOptions(options);
9-
10-
expect(result.cache).toBe(true);
11-
});
12-
13-
test("cache is enabled in watch mode by default", () => {
14-
const options = { watch: true, cache: () => true };
15-
const helper = new WebpackOptionHelper();
16-
17-
const result = helper.filterOptions(options);
18-
19-
expect(result.cache).toBe(true);
20-
});
21-
22-
test("cache is disabled in normal mode by default", () => {
23-
const options = { watch: false, cache: () => true };
24-
const helper = new WebpackOptionHelper();
25-
26-
const result = helper.filterOptions(options);
27-
28-
expect(result.cache).toBe(false);
29-
});
30-
31-
test("cache is disabled in normal mode", () => {
32-
const options = { watch: false, cache: true };
33-
const helper = new WebpackOptionHelper();
34-
35-
const result = helper.filterOptions(options);
36-
37-
expect(result.cache).toBe(false);
38-
});
39-
404
test("watch options is part of webpack options", () => {
415
const options = {
426
watch: true,

src/options/default.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ const webpackOptions = {
2626
cachedAssets: false,
2727
colors: true,
2828
},
29-
cache: (options) => {
30-
// if watch enabled also default to cache true
31-
return Array.isArray(options)
32-
? options.some((option) => option.watch)
33-
: !!options.watch;
34-
},
3529
};
3630

3731
const webpackDevServerOptions = {

src/plugins/CachePluginFactory.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

tasks/webpack.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
const webpack = require("webpack");
44
const pkg = require("../package.json");
55
const OptionHelper = require("../src/options/WebpackOptionHelper");
6-
const CachePluginFactory = require("../src/plugins/CachePluginFactory");
76
const ProgressPluginFactory = require("../src/plugins/ProgressPluginFactory");
87

98
module.exports = (grunt) => {
10-
const cachePluginFactory = new CachePluginFactory();
119
const processPluginFactory = new ProgressPluginFactory(grunt);
1210

1311
grunt.registerTask(
@@ -59,9 +57,6 @@ module.exports = (grunt) => {
5957

6058
const compiler = webpack(webpackOptions);
6159

62-
if (opts.cache) {
63-
cachePluginFactory.addPlugin(target, compiler);
64-
}
6560
if (opts.progress) {
6661
processPluginFactory.addPlugin(compiler, webpackOptions);
6762
}

0 commit comments

Comments
 (0)