Skip to content

Commit fae38a3

Browse files
danezsnickell
andauthored
Call compiler.close() so webpack writes cache to disk (#252)
* Call compiler.close() so webpack writes cache to disk * Version with minimal diff / local changes only (tested, works) * chore: lint --------- Co-authored-by: Seth Nickell <[email protected]>
1 parent 33b1ddf commit fae38a3

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tasks/webpack.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ module.exports = (grunt) => {
3333
return;
3434
}
3535

36+
const compilerClosePromises = [];
37+
3638
targets.forEach((target) => {
3739
if (target === "options") {
3840
runningTargetCount--;
@@ -61,9 +63,9 @@ module.exports = (grunt) => {
6163
processPluginFactory.addPlugin(compiler, webpackOptions);
6264
}
6365

64-
const handler = (err, stats) => {
65-
if (err) {
66-
done(err);
66+
const handler = (webpackErr, stats) => {
67+
if (webpackErr) {
68+
done(webpackErr);
6769
return;
6870
}
6971

@@ -97,7 +99,18 @@ module.exports = (grunt) => {
9799

98100
keepalive = keepalive || opts.keepalive;
99101

100-
if (--runningTargetCount === 0 && !keepalive) done();
102+
if (!keepalive) {
103+
compilerClosePromises.push(
104+
new Promise((resolve, reject) =>
105+
compiler.close((err) => (err ? reject(err) : resolve())),
106+
),
107+
);
108+
if (--runningTargetCount === 0) {
109+
Promise.all(compilerClosePromises)
110+
.then(() => done())
111+
.catch((err) => done(err));
112+
}
113+
}
101114
};
102115

103116
if (opts.watch) {

0 commit comments

Comments
 (0)